// get a reference to the MemberGroupService
var memberGroupService = Services.MemberGroupService;
// Create a new membergroup 'in code'
IMemberGroup newMemberGroup = new MemberGroup() { Name = "LovelyPeople" };
// use the MemberGroupServer to persist the new Member Group to Umbraco
memberGroupService.Save(newMemberGroup);
var memberService = Services.MemberService;
// create member
var newMember = memberService.CreateMember("JezzaB", "[email protected]", "Jeremy Bourbon", "Member");
memberService.Save(newMember);
memberService.AssignRole(newMember.Id, "LovelyPeople");
// but also I think this works
memberService.AssignRole(newMember.Id, "NotPreviouslyCreatedMemberGroupName");
// eg if you are assigning a member to a new member group, I'm not sure you need to have created the member group programatically 'before', assigning to a 'new' member group, will trigger the creation of that group.
// also be careful with case sensitivity, as unless it's been fixed recently lovelyPeople != LovelyPeople...
Create Member Groups & Properties Programatically in umbraco 8
Is it possible to create a member group and member group properties programmatically?
I have the need to create a specific Member Group programatically and then add specific properties to it, this is for a package I'm creating.
Hi Yuvraj
You can use the MemberGroupService to create a Member Group programmatically:
https://our.umbraco.com/Documentation/Reference/Management/Services/MemberGroupService/Index-v8
and the MemberService to Create Members:
https://our.umbraco.com/Documentation/Reference/Management/Services/MemberService/Index-v8
if that helps?
regards
Marc
Hi Marc Goodson
Can you provide an example, how to create member groups & Properties Programmatically?
Hi Yuvraj
Yes, I think it's something like this:
regards
marc
Hi Marc Goodson
But I need to Create Group & Properties Programmatically in member document type please see the image below:-
Hi Yuvraj
Sorry my misunderstanding!
You probably want the MemberTypeService: https://our.umbraco.com/Documentation/Reference/Management/Services/MemberTypeService/Index-v8
which allows you to programmatically create MemberType definitions.
regards
Marc
Hi Marc Goodson
A request, Can you provide an example, how to create member groups & Properties Programmatically?
Here is an example from my code:
is working on a reply...