Managing group roles

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can add a role to a group:

 

[C#]

 

using CMS.Community;

using CMS.SiteProvider;

using CMS.CMSHelper;

 

...

 

        // Get group object

      GroupInfo gi = GroupInfoProvider.GetGroupInfo("CustomGroup", "CorporateSite");

     

      // If group exists

      if (gi != null)

       {

          // Create role object

          RoleInfo ri = new RoleInfo();

 

          // Set role properties

           ri.RoleName = "CustomGroupRole";

           ri.DisplayName = "Custom group role";

           ri.RoleGroupID = gi.GroupID;

           ri.SiteID = CMSContext.CurrentSiteID;

 

          // Save role to database

          RoleInfoProvider.SetRoleInfo(ri);

       }

 

The following sample code shows how you can add a group member to a group role:

 

[C#]

 

using CMS.SiteProvider;

 

...

 

      // Get role object

      RoleInfo ri = RoleInfoProvider.GetRoleInfo("CustomGroupRole", "CorporateSite");

 

      // Get user object

      UserInfo ui = UserInfoProvider.GetUserInfo("CustomGroupMember");

 

      // If role and user exist

      if ((ri != null) && (ui != null))

       {

          // Add user to role

          UserRoleInfoProvider.AddUserToRole(ui.UserID, ri.RoleID);

       }

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?managing_group_roles.htm