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 01, 2014 @ 23:13
    Jesper
    0

    Add membergroup to node in code - Umbraco 7

    Hello!

    How can I programmatically add 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<IContent> 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...
               }
                }
            }
Please Sign in or register to post replies

Write your reply to:

Draft