Access custom member type properties ModelsBuilder strongly typed
I am trying to make a page where a logged in user can edit his account details. In the backoffice I created a custom Member Type called "Gebruiker" with some custom member properties, like Name, Last name, Address etc..
However, whenever i try to access the currently active user's properties through the MemberService:
var actieveUser = Services.MemberService.GetByUsername(Membership.GetUser().UserName);
The activeUser only contains the 'standard' member properties, like email and name, and not the properties from my "Gebruiker" Member Type. By using the GetValue Method i am able to get my property values, but i would like to achieve this through the strongly typed models instead of property's alias as a string
var naam = actieveUser.GetValue("Naam");
var postcode = actieveUser.GetValue("Postcode");
Is there a way to access the active user and instantiate a "Gebruiker" object from which i can access all my custom and standard member properties?
For example:
The Umbraco ModelsBuilder doesn't serialize Members, so what I would recommend is creating either a wrapper class or extension method on the "GetByUsername()" method, in which you define a custom Member model with your custom properties to pass your fetched member into. In your constructor you can then store the GetValue() calls so that, while it's not strongly typed, it's only one model that ever references the values by string, and allows you to work with your own custom Model throughout the rest of the application!
Thanks for the insight . I managed to get the basics to work through Get & SetValue() calls, but i like your suggestion of a wrapper class more. Ill try to set up something like that.
Access custom member type properties ModelsBuilder strongly typed
I am trying to make a page where a logged in user can edit his account details. In the backoffice I created a custom Member Type called "Gebruiker" with some custom member properties, like Name, Last name, Address etc..
However, whenever i try to access the currently active user's properties through the MemberService:
The activeUser only contains the 'standard' member properties, like email and name, and not the properties from my "Gebruiker" Member Type. By using the GetValue Method i am able to get my property values, but i would like to achieve this through the strongly typed models instead of property's alias as a string
Is there a way to access the active user and instantiate a "Gebruiker" object from which i can access all my custom and standard member properties? For example:
Hi Rick,
The Umbraco ModelsBuilder doesn't serialize Members, so what I would recommend is creating either a wrapper class or extension method on the "GetByUsername()" method, in which you define a custom Member model with your custom properties to pass your fetched member into. In your constructor you can then store the GetValue() calls so that, while it's not strongly typed, it's only one model that ever references the values by string, and allows you to work with your own custom Model throughout the rest of the application!
Kind regards,
Corné
Hi Corné,
Thanks for the insight . I managed to get the basics to work through Get & SetValue() calls, but i like your suggestion of a wrapper class more. Ill try to set up something like that.
Cheers!
Rick
is working on a reply...