Copied to clipboard

Flag this post as spam?

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


  • Yuvraj Singh 14 posts 103 karma points
    25 days ago
    Yuvraj Singh
    0

    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.

    enter image description here

  • Marc Goodson 1622 posts 10744 karma points MVP 6x c-trib
    23 days ago
    Marc Goodson
    0

    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

  • Yuvraj Singh 14 posts 103 karma points
    22 days ago
    Yuvraj Singh
    0

    Hi Marc Goodson

    Can you provide an example, how to create member groups & Properties Programmatically?

  • Marc Goodson 1622 posts 10744 karma points MVP 6x c-trib
    19 days ago
    Marc Goodson
    0

    Hi Yuvraj

    Yes, I think it's something like this:

                // 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...
    

    regards

    marc

  • Yuvraj Singh 14 posts 103 karma points
    17 days ago
    Yuvraj Singh
    0

    Hi Marc Goodson

    But I need to Create Group & Properties Programmatically in member document type please see the image below:-

    enter image description here

    enter image description here

  • Marc Goodson 1622 posts 10744 karma points MVP 6x c-trib
    16 days ago
    Marc Goodson
    0

    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

  • Yuvraj Singh 14 posts 103 karma points
    1 week ago
    Yuvraj Singh
    0

    Hi Marc Goodson

    A request, Can you provide an example, how to create member groups & Properties Programmatically?

Please Sign in or register to post replies

Write your reply to:

Draft