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 31 posts 141 karma points
    Nov 08, 2021 @ 11:13
    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 2155 posts 14406 karma points MVP 9x c-trib
    Nov 10, 2021 @ 09:42
    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 31 posts 141 karma points
    Nov 11, 2021 @ 05:10
    Yuvraj Singh
    0

    Hi Marc Goodson

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

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Nov 14, 2021 @ 11:09
    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 31 posts 141 karma points
    Nov 16, 2021 @ 06:11
    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 2155 posts 14406 karma points MVP 9x c-trib
    Nov 17, 2021 @ 09:15
    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 31 posts 141 karma points
    Nov 24, 2021 @ 13:40
    Yuvraj Singh
    0

    Hi Marc Goodson

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

  • Janus Kamp Hansen 16 posts 153 karma points
    Jan 28, 2022 @ 10:24
    Janus Kamp Hansen
    0

    Here is an example from my code:

                                    // Creates user group
                                UserGroup userGroup = new UserGroup();
                                userGroup.Name = $"{config.SiteName} User Group";
                                userGroup.Alias = string.Concat("ug_", root.Id, "_", userGroup.Name.Replace(" ", ""));
    
                                userGroup.AddAllowedSection("content");
                                userGroup.AddAllowedSection("media");
                                userGroup.Permissions = new List<string> { "I", "P", "K", "F", "ï", "D", "C", "U", "A", "O", "S" };
    
                                userGroup.StartContentId = root.Id;
                                userGroup.StartMediaId = rootMedia.Id;
    
                                userGroup.Icon = "icon-location-near-me";
    
                                Services.UserService.Save(userGroup);
    
Please Sign in or register to post replies

Write your reply to:

Draft