The following sample code shows how you can add the user gold as a member of the group:
[C#]
using System; using CMS.Community; using CMS.SiteProvider; using CMS.UIControls; using CMS.CMSHelper;
...
string groupName = "customGroupName"; string siteName = "CommunitySite";
// Get group object GroupInfo gi = GroupInfoProvider.GetGroupInfo(groupName, siteName);
// If group exist if (gi != null) { // Get user object UserInfo ui = UserInfoProvider.GetUserInfo("gold");
// If user exists if (ui != null) { // Create new group member object GroupMemberInfo gmi = new GroupMemberInfo();
//Set properties of member gmi.MemberGroupID = gi.GroupID; gmi.MemberApprovedByUserID = CurrentUser.UserID; gmi.MemberApprovedWhen = DateTime.Now; gmi.MemberInvitedByUserID = CurrentUser.UserID; gmi.MemberUserID = ui.UserID; gmi.MemberJoined = DateTime.Now;
// Save object to database GroupMemberInfoProvider.SetGroupMemberInfo(gmi); } } |
The following sample code shows how you can remove the user gold from the group:
[C#]
using CMS.Community; using CMS.SiteProvider;
...
// Get user object UserInfo ui = UserInfoProvider.GetUserInfo("gold");
// If user exists if (ui != null) {
int userID = ui.UserID; int groupID = 13;
// Get group member object by UserID and GroupID GroupMemberInfo gmi = GroupMemberInfoProvider.GetGroupMemberInfo(userID, groupID);
// Delete group member object from database GroupMemberInfoProvider.DeleteGroupMemberInfo(gmi);
// Delete group member object from database by GroupMemberID GroupMemberInfoProvider.DeleteGroupMemberInfo(1); } |
The following sample code shows how you can modify the Comment property of a group member:
[C#]
using CMS.Community;
...
// Get group member object by GroupMemberID GroupMemberInfo gmi = GroupMemberInfoProvider.GetGroupMemberInfo(1);
// Change member comment property gmi.MemberComment = gmi.MemberComment + " Updated";
// Save object GroupMemberInfoProvider.SetGroupMemberInfo(gmi); |
The following sample code shows how you can get a DataSet containing all group members in the system with a GroupMemberID greater than 2, ordered by their GroupMemberID:
[C#]
using System.Data; using CMS.Community;
...
string where = "MemberID > 5"; string orderBy = "MemberID";
// Get DataSet of group member objects DataSet ds = GroupMemberInfoProvider.GetGroupMembers(where, orderBy); |
Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_managing_group_members.htm