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;
...
// Get group object by GroupName and SiteName 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) { // Get group member object by UserID and GroupID GroupMemberInfo gmi = GroupMemberInfoProvider.GetGroupMemberInfo(ui.UserID, 13);
// 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;
...
// Get DataSet of group member objects DataSet ds = GroupMemberInfoProvider.GetGroupMembers("GroupMemberID > 2", "GroupMemberID"); |
Page url: http://devnet.kentico.com/docs/devguide/index.html?managing_group_members.htm