I'm about to save some values as new attributes to Member object. To do that I wish to know a method that can save extra datas to Member profile. See how I do that in the example code below:
//Employee record updation code
public string UpdateEmployee(Employee empObject)
{
if (isAdminOrDirector)
{
var checkMember = ApplicationContext.Current.Services.MemberService.GetById(empObject.Id);
if (checkMember != null)
{
checkMember.Name = empObject.Name;
checkMember.Email = empObject.Email;
//Add extra attributes to member
Attribute attr1 = New Attribute("Key1", "Value1");
Attribute attr2 = New Attribute("Key2", "Value2");
Attribute attr3 = New Attribute("Key3", "Value3");
checkMember.ExtraAttributes.Add(attr1);
checkMember.ExtraAttributes.Add(attr2);
checkMember.ExtraAttributes.Add(attr3);
try
{
ApplicationContext.Current.Services.MemberService.Save(checkMember);
return "Employee Updated Successfully";
}
catch (Exception ex)
{
umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, 0,
string.Format("Update Employee Error | ElmanagementController | UpdateEmployee | " + ex.Message));
return "Invalid Employee";
}
}
else
{
return "Invalid Employee";
}
}else
{
return "You don't have permission to do this!";
}
}
Using ApplicationContext.Current.Services.MemberService I can get Member object by ID. I want to add some extra attributes to the member object, just like this code block:
//Add extra attributes to member
Attribute attr1 = New Attribute("Key1", "Value1");
Attribute attr2 = New Attribute("Key2", "Value2");
Attribute attr3 = New Attribute("Key3", "Value3");
checkMember.ExtraAttributes.Add(attr1);
checkMember.ExtraAttributes.Add(attr2);
checkMember.ExtraAttributes.Add(attr3);
You see, I want to add some custom attributes to Member and then get those attributes out, but don't know how, and the code above just an example to let you know my ideas.
Please note: if you use the MemberService to do all of this, it goes straight to the database and will cause performance problems. If you don't have to change any data then please please use the MembershipHelper as much as you can.
How to add more properties to exist member?
Hello,
I have done research on Member and see that it has some certain properties like: Username, Email, Name etc...
I want to add more custom properties to Member like: Job Title, Year Old, Number of Children, Material Status etc...
Is there a way to do that in C#?
Note: I don't want to change the structure of Member table from Umbraco Database or add more properties to exist class or entity.
Good, never change the database you get with Umbraco, that will break your upgrade path.
Go into the members section, change the member type and you're good to go!
Hi Sebastiaan,
I'm about to save some values as new attributes to Member object. To do that I wish to know a method that can save extra datas to Member profile. See how I do that in the example code below:
Using ApplicationContext.Current.Services.MemberService I can get Member object by ID. I want to add some extra attributes to the member object, just like this code block:
You see, I want to add some custom attributes to Member and then get those attributes out, but don't know how, and the code above just an example to let you know my ideas.
Hope you could help.
That's not the way to do it :-)
Make sure to read the documentation on working with the members section: https://our.umbraco.org/documentation/getting-started/data/members/
And here's some ideas on how you would use the MembershipHelper to query data on the members: http://24days.in/umbraco/2014/dealing-with-members/
Please note: if you use the MemberService to do all of this, it goes straight to the database and will cause performance problems. If you don't have to change any data then please please use the MembershipHelper as much as you can.
Additionally, there's a chapter about how to work with members on Umbraco.tv - I highly recommend you watch it: http://umbraco.tv/videos/umbraco-v7/content-editor/administrative-content/members/what-is-a-member/
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.