The following example adds a user as a member of a group.
privatebool CreateGroupMember() {
// Get the group GroupInfo group = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
if (group != null) {
// Get the user UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName);
if (user != null) { // Create new group member object GroupMemberInfo newMember = newGroupMemberInfo(); //Set the properties newMember.MemberGroupID = group.GroupID; newMember.MemberApprovedByUserID = CurrentUser.UserID; newMember.MemberApprovedWhen = DateTime.Now; newMember.MemberInvitedByUserID = CurrentUser.UserID; newMember.MemberUserID = user.UserID; newMember.MemberJoined = DateTime.Now; newMember.MemberComment = "New member added by API example."; // Save the member GroupMemberInfoProvider.SetGroupMemberInfo(newMember); } returntrue; } returnfalse; }
The following example gets and updates a group member.
privatebool GetAndUpdateGroupMember() {
// Get the group GroupInfo group = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
if (group != null) {
// Get the user UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName);
if (user != null) {
// Get the group member GroupMemberInfo updateMember = GroupMemberInfoProvider.GetGroupMemberInfo(user.UserID, group.GroupID);
if (updateMember != null) {
// Update the properties updateMember.MemberComment = updateMember.MemberComment.ToLower();
// Save the changes GroupMemberInfoProvider.SetGroupMemberInfo(updateMember); returntrue; } } } returnfalse; }
The following example gets and bulk updates group members.
privatebool GetAndBulkUpdateGroupMembers() { // Prepare the parameters string where = "MemberUserID =" + CMSContext.CurrentUser.UserID; // Get the data DataSet members = GroupMemberInfoProvider.GetGroupMembers(where, null); if (!DataHelper.DataSourceIsEmpty(members)) { // Loop through the individual items foreach (DataRow memberDr in members.Tables[0].Rows) { // Create object from DataRow GroupMemberInfo modifyMember = newGroupMemberInfo(memberDr); // Update the properties modifyMember.MemberComment = modifyMember.MemberComment.ToUpper(); // Save the changes GroupMemberInfoProvider.SetGroupMemberInfo(modifyMember); } returntrue; } returnfalse; }
The following example removes a member from a group.
privatebool DeleteGroupMember() {
// Get the group GroupInfo group = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
if (group != null) {
// Get the user UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName);
if (user != null) {
// Get the group member GroupMemberInfo deleteMember = GroupMemberInfoProvider.GetGroupMemberInfo(user.UserID, group.GroupID);
if (deleteMember != null) { // Save the changes GroupMemberInfoProvider.DeleteGroupMemberInfo(deleteMember); returntrue; } } } returnfalse; }
The following example creates an invitation to a group for a user.
privatebool CreateInvitation() { // Get the group GroupInfo group = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
if (group != null) { // Create new invitation InvitationInfo newInvitation = newInvitationInfo();
// Set properties newInvitation.InvitationComment = "Invitation created by API example."; newInvitation.InvitationGroupID = group.GroupID; newInvitation.InvitationUserEmail = "admin@localhost.local"; newInvitation.InvitedByUserID = CMSContext.CurrentUser.UserID; newInvitation.InvitationCreated = DateTime.Now; newInvitation.InvitationValidTo = DateTime.Now.AddDays(1);
// Save object InvitationInfoProvider.SetInvitationInfo(newInvitation);