Kentico CMS 7.0 Developer's Guide

Managing groups

Managing groups

Previous topic Next topic Mail us feedback on this topic!  

Managing groups

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

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a group.

 

private void CreateGroup()
{
    // Create new group object
    GroupInfo newGroup = new GroupInfo();
 
    // Set the properties
    newGroup.GroupDisplayName = "My new group";
    newGroup.GroupName = "MyNewGroup";
    newGroup.GroupSiteID = CMSContext.CurrentSiteID;
    newGroup.GroupDescription = "";
    newGroup.GroupApproveMembers = GroupApproveMembersEnum.AnyoneCanJoin;
    newGroup.GroupAccess = CMS.SiteProvider.SecurityAccessEnum.AllUsers;
    newGroup.GroupApproved = true;
    newGroup.GroupApprovedByUserID = CurrentUser.UserID;
    newGroup.GroupCreatedByUserID = CurrentUser.UserID;
    newGroup.AllowCreate = SecurityAccessEnum.GroupMembers;
    newGroup.AllowDelete = SecurityAccessEnum.GroupMembers;
    newGroup.AllowModify = SecurityAccessEnum.GroupMembers;
    newGroup.GroupNodeGUID = Guid.Empty;
 
    // Save the group
    GroupInfoProvider.SetGroupInfo(newGroup);
}

 

The following example gets and updates a group.

 

private bool GetAndUpdateGroup()
{

  // Get the group
  GroupInfo updateGroup = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);

    if (updateGroup != null)
    {
        // Update the properties
        updateGroup.GroupDisplayName = updateGroup.GroupDisplayName.ToLower();
 
        // Save the changes
        GroupInfoProvider.SetGroupInfo(updateGroup);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates groups.

 

private bool GetAndBulkUpdateGroups()
{
    // Prepare the parameters
    string where = "GroupName LIKE N'MyNewGroup%'";
 
    // Get the data
    DataSet groups = GroupInfoProvider.GetGroups(where, null);
    if (!DataHelper.DataSourceIsEmpty(groups))
    {
        // Loop through the individual items
        foreach (DataRow groupDr in groups.Tables[0].Rows)
        {
            // Create object from DataRow
            GroupInfo modifyGroup = new GroupInfo(groupDr);

 
          // Update the properties
           modifyGroup.GroupDisplayName = modifyGroup.GroupDisplayName.ToUpper();

 
            // Save the changes
            GroupInfoProvider.SetGroupInfo(modifyGroup);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a group.

 

private bool DeleteGroup()
{

  // Get the group
  GroupInfo deleteGroup = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);

 
    // Delete the group
    GroupInfoProvider.DeleteGroupInfo(deleteGroup);
 
    return (deleteGroup != null);
}