Copied to clipboard

Flag this post as spam?

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


  • Jesper 8 posts 51 karma points
    Oct 03, 2014 @ 09:20
    Jesper
    0

    Add membergroup to node programmatically - Umbraco 7

    Hello!

    I'm struggling with programmatically adding a membergroup to a node.

    I'm creating a membergroup if a page of a certain contenttype is created, hooking on to the Saved event. Then I want to add that membergroup to the current node to set access rights.

    Any ideas on how to do this? This is my code so far:

    private void ContentService_Saved(IContentService sender, SaveEventArgs e)
            {
                foreach (var content in e.SavedEntities)
                {
                    if (content != null && content.ContentType.Alias == "Unitpage")
                    {
                        var service = new MemberGroupService(new RepositoryFactory());

                        var membergroup = new MemberGroup();

                        membergroup.Name = string.Format("Unit_{0}", content.Id);
                        membergroup.CreatorId = 0;
    service.Save(membergroup);

    // add membergroup to content node here to set acccess rights
    // do something...
               }
                }
            }

    Best,
    jesper

Please Sign in or register to post replies

Write your reply to:

Draft