Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Larsen 116 posts 381 karma points
    Sep 22, 2014 @ 10:16
    Daniel Larsen
    0

    Getting custom property from member u7

    Hi, can one of you tell me, what is wrong here? :-)

    It is a partial view, and I want to retrieve the custom property of a member into a variable, because I want to do a check on it later.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using umbraco.cms.businesslogic.member;
    @using Umbraco.Core;
    @using Umbraco.Core.Services;
    
    @{
        // Find the current member
        var member = Member.GetCurrentMember();
    
        if (member != null)
        {
            var prop = member.getProperty("PhoneLocal").Value;
    
            <h1>@prop</h1>
    
            // Update the member
            member.SetValue("PhoneLocal", "01234567890");
    
            // Save the member
            member.Save();
        }
    }
    

    Thank you!

    /Daniel

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 22, 2014 @ 10:33
    Dan Lister
    1

    Hi Daniel,

    Try the below. I think you are getting the old and new Member API's mixed up. Note the correct SetProperty() method call. As a side note, you are using the old Member API. It might be best off using the new Member Service APi.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using umbraco
    @using umbraco.cms.businesslogic.member
    
    @{
        // Find the current member
        var member = Member.GetCurrentMember();
    
        if (member != null)
        {
            var prop = member.GetProperty<string>("PhoneLocal");
    
            <h1>@prop</h1>
    
            // Update the member
            member.SetProperty("PhoneLocal", "01234567890");
    
            // Save the member
            member.Save();
        }
    }
    

    Thanks, Dan.

  • Daniel Larsen 116 posts 381 karma points
    Sep 22, 2014 @ 10:48
    Daniel Larsen
    0

    Let me get this straight. The example you posted above, is that the old or new member service?

    It is complaining about the GetCurrentMember :-/

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0104: 'Member' is an ambiguous reference between 'Umbraco.Core.Models.Member' and 'umbraco.cms.businesslogic.member.Member'

    Source Error:

    Line 5: @{

    Line 6: // Find the current member

    Line 7: var member = Member.GetCurrentMember();

    Line 8:

    Line 9: if (member != null)

    Thank you for helping me :-)

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 22, 2014 @ 10:50
    Dan Lister
    1

    Hi Daniel,

    The way above is the old way. To fix your error now, add the following line:

    @using Member = umbraco.cms.businesslogic.member.Member
    

    Thanks, Dan.

  • Daniel Larsen 116 posts 381 karma points
    Sep 22, 2014 @ 10:54
    Daniel Larsen
    0

    Is this the new way then or am I completly confused/lost?

    @{
        // Find the current member
        var membershipUser = Membership.GetUser();
        if (membershipUser != null)
        {
            var membershipUsername = membershipUser.UserName;
            var m = ApplicationContext.Services.MemberService.GetByUsername(membershipUsername);
            var prop = m.getProperty("PhoneLocal").Value;
    
            <h1>@prop</h1>
            // Update the member
            member.SetValue("PhoneLocal", "01234567890");
    
            // Save the member
            ApplicationContext.Services.MemberService.Save(member);
        }
    }
    

    Thank you :-)

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 22, 2014 @ 10:55
    Dan Lister
    1

    Yeah thats the new way. Take a look here for more information.

    Thanks, Dan.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 22, 2014 @ 11:09
    Jeroen Breuer
    1

    Hello,

    Do you only want to get data or also update it? The member service is for updating data and does direct calls to the database and can be pretty slow. It's better to use Umbraco.TypedMember which returns the member as an IPublishedContent (like content and media). This has better perfomance. More info here: http://issues.umbraco.org/issue/U4-4379#comment=67-12760

    Jeroen

  • Daniel Larsen 116 posts 381 karma points
    Sep 22, 2014 @ 12:15
    Daniel Larsen
    0

    I need to get and update data :-)

    I get this error with the getproperty: 'Umbraco.Core.Models.IMember' does not contain a definition for 'getProperty' and no extension method 'getProperty' accepting a first argument of type 'Umbraco.Core.Models.IMember' could be found (are you missing a using directive or an assembly reference?)

    Thank you :-)

  • Dan Lister 416 posts 1974 karma points c-trib
    Sep 22, 2014 @ 12:19
    Dan Lister
    101

    Try...

    var prop = m.GetValue("PhoneLocal");
    

    Thanks, Dan.

  • Daniel Larsen 116 posts 381 karma points
    Sep 22, 2014 @ 12:28
    Daniel Larsen
    0

    Thank you very much! :-D

    I hope you'll have a nice day!

    /Daniel

Please Sign in or register to post replies

Write your reply to:

Draft