Copied to clipboard

Flag this post as spam?

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


  • Tony 105 posts 163 karma points
    Jun 19, 2019 @ 15:29
    Tony
    1

    Members and Custom Profiles

    I have a number of custom member types with different properties. How do I go about getting a member and read/update those properties?

    I can see the Model builder has created them but I can't find anything in the Membership service or MemebershipHelper etc?

    In Content Im able to cast it to the correct object (although AsType<> was much easier), but I cant see how to get an editable member of a type?

  • Tarik | WPPlumber 179 posts 801 karma points c-trib
    Jun 19, 2019 @ 17:20
    Tarik | WPPlumber
    0

    I suggest the following:

    How do I go about getting a member and read/update those properties?

    Use MemberTypeService functions Get(string alias) and Save(IMemberType memberType)

    I can see the Model builder has created them but I can't find anything in the Membership service or MemebershipHelper etc?

    In Content Im able to cast it to the correct object (although AsType<> was much easier), but I cant see how to get an editable member of a type?

    The built-in service already exist for MemberType.

    Note:

    The MemberTypeService is available through the ApplicationContext, but the if you are using a SurfaceController or the UmbracoUserControl then the MemberTypeService is available through a local Services property

  • Tony 105 posts 163 karma points
    Jun 20, 2019 @ 08:46
    Tony
    0

    I dont really want to have to use those 'GetValue' though as I already have the model that the model builder created. I would end up just duplicating the class?

    The membertype service would just return the member type rather than the member as a concrete instance of a type though wouldn't it?

    I was hoping I would be able to do something like

    var myMember = memberService.GetCurrentMember().TryConvertTo<MyMemberClass>()
    

    That would then create a proper instance so I wouldn't have to manually add in the Get methods which are prone to change. From that I could call memberservice.Save(myMember).

  • Tarik | WPPlumber 179 posts 801 karma points c-trib
    Jun 20, 2019 @ 10:13
    Tarik | WPPlumber
    0

    The membertype service would just return the member type rather than the member as a concrete instance of a type though wouldn't it?

    I see what you mentioned correct because of this.

    I suggest Frans' answer for using the ModelsBuilder and for performance I suggest Sebastiaan Janssen' post and for more speed this.

  • Tony 105 posts 163 karma points
    Jun 20, 2019 @ 14:20
    Tony
    0

    After looking at teh model build I don't think that would work as its just got getters and not setters which is fine for some areas but not when I want to update the member.

    For example, I need to set a password reset code & datetime stamp on their profile in two custom fields but there doesn't seem to be any way to achieve this?

  • Tarik | WPPlumber 179 posts 801 karma points c-trib
    Jun 20, 2019 @ 19:30
    Tarik | WPPlumber
    100

    I used the following code and the country property changed successfully.

    @using Umbraco.Core;
    @using Umbraco.Core.Services;
    var memberService = Services.MemberService;
    var member = memberService.GetByEmail("[email protected]");
    member.SetValue("country", "Morocco");
    memberService.Save(member);
    
  • Rhys Hamilton 140 posts 942 karma points
    Jun 20, 2019 @ 15:11
    Rhys Hamilton
    1

    For all intensive purposes, ModelsBuilder really just returns read-only models (as you've rightly pointed out).

    Since you're not able to set the values, what you're looking to achieve isn't possible straight out of the box - and I'm not entirely sure there's an option to change or configure this to produce both getters and setters.

    As such, you'll probably have to use something likememberService.SetValue("yourPropertyAlias", "yourNewValue") to set new property methods.

    It might not be ideal, but looks like the only option at the moment.

  • Tony 105 posts 163 karma points
    Jun 21, 2019 @ 13:45
    Tony
    0

    Yeah, I think I was asking too much :(. Would be great to have to option to get a model and have setters to write to umbraco though

Please Sign in or register to post replies

Write your reply to:

Draft