x First time here? Check out the FAQ

Come work for Umbraco - The Umbraco HQ are hiring Project managers, .NET developers and DevOps people!

  • Avatar36posts56karma

    Get member by ID

    Kresten Banke started this topic May 4, 2010 @ 09:30, Go directly to the topic solution

    Hey all,

    It is possible to get a member with various keys such as username, email etc.

    Isn't it possible to get the member using the member ID?

    Kind regards

    Kresten


  • Avatar1177posts3665karma
    adminComment with ID: 32500
    Dennis Aaen posted this reply May 4, 2010 @ 09:56

    Hi Kresten,

    It is possible to get a member using the member id.

    You can make a XSLT-file and use this Umbraco Extension

    umbraco.library:GetMember(Int 32 MemberId) 

    Then you will get a member by an ID

    I haven´t try it myself, but hopefully it will solve your problem.

    Reards

    Dennis Aaen

     


  • Avatar36posts56karma
    Comment with ID: 32502
    Kresten Banke posted this reply May 4, 2010 @ 10:23

    Thanks - I'm a total newbe on xslt and I need to fetch the member from a usercontrol.

    Is there any way to do that?


  • Avatar1177posts3665karma
    adminComment with ID: 32504
    Dennis Aaen posted this reply May 4, 2010 @ 10:33

    I haven´t worked with usercontrols in Umbraco yet,


  • Avatar4382posts5128karma
    adminComment with ID: 32505
    Dirk De Grave posted this reply May 4, 2010 @ 10:54

    Kresten,

    there's two options:

    - use the member api, some docs can be found here

    - use the membership api. A great overview can be found on the wiki

     

    Cheers,

    /Dirk


  • Avatar36posts56karma
    Comment with ID: 32509
    Kresten Banke posted this reply May 4, 2010 @ 11:18

    Thanks - as I wrote I have found various methods for getting a member - i.e. by email, username etc.

    However, I store a memberID in a DB and want to be able to fetch the member using this key. Is that possible, or should I use a different key - such as username?


  • Simon Kibsgård posted this reply May 16, 2010 @ 09:16

    Hi Kresten

    You can go like this: 

    Member m = new Member(MemberId);

    /Simon K


  • Avatar36posts56karma
    Comment with ID: 33417
    Kresten Banke posted this reply May 16, 2010 @ 09:26

    Hi Simon,

    That will give me a new member, but I doens't allow me to access properties of the member with ID = x.

    Instead of saving the memberID in my db, I guess I'll just save the username - though it isn't the best solution...


  • Jan Skovgaard posted this reply May 16, 2010 @ 09:56

    Hi Kresten

    Will this not give you the id that you neeed?

    m = Member.GetCurrentMember();

    Then you should be able to fetch the ID by using this line, right?

    m.Id

    Please do note that I'm no .NET wizard but I just played a bit around with this and seems to me like it's working.

    /Jan


  • Avatar36posts56karma
    Comment with ID: 33560
    Kresten Banke posted this reply May 17, 2010 @ 10:54

    Hi - It's seems that I haven't explained the problem well enough.

    I need to store information about a purchase. One information data about who has actually purchase an item. I store the memberID in a db in order to fetch the member - and related properties - again. I would like to use the ID as a key for fetching the member since this is an integer an easy to use with linq/sql.

    However, when I want to fetch information about the "buyer", how can I do this, when all I have is the ID?

    Currently - as a work-aroung - I am storing both the ID and the loginname, since it is possible to fetch the member by loginname. However, this isn't very pretty...

    Any solutions for fetching a member from the memberID?

    Regards,

    Kresten


  • Avatar44posts65karma
    Comment with ID: 33566
    Kevin Farrow posted this reply May 17, 2010 @ 11:33

    i think you'll find Simon is correct...

    umbraco.cms.businesslogic.member;

    ...

       Member m = new Member(memberId);

    i.e. new Member(memberId) doesn't create a new member, it gets the Member's details using the memberId you pass in.

    if you need to create a new member then you would use:

    Member m = Member.MakeNew(...);

    or to get the current member (as Jan says):

    Member m = Member.GetCurrentMember().Id;

    Regards,
    Kevin


Please login or Sign up To post replies