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
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).
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?
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.
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?
I suggest the following:
Use
MemberTypeService
functions Get(string alias) and Save(IMemberType memberType)The built-in service already exist for
MemberType
.Note:
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
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).
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.
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?
I used the following code and the country property changed successfully.
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 like
memberService.SetValue("yourPropertyAlias", "yourNewValue")
to set new property methods.It might not be ideal, but looks like the only option at the moment.
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
is working on a reply...