Groups


List of examples:

Groups

Creating a group




// Creates a new group object
GroupInfo newGroup = new GroupInfo();

// Sets the properties for the group
newGroup.GroupDisplayName = "New group";
newGroup.GroupName = "NewGroup";
newGroup.GroupSiteID = SiteContext.CurrentSiteID;
newGroup.GroupDescription = "";
newGroup.GroupApproveMembers = GroupApproveMembersEnum.AnyoneCanJoin;
newGroup.GroupAccess = SecurityAccessEnum.AllUsers;
newGroup.GroupApproved = true;
newGroup.GroupApprovedByUserID = MembershipContext.CurrentUserProfile.UserID;
newGroup.GroupCreatedByUserID = MembershipContext.CurrentUserProfile.UserID;
newGroup.AllowCreate = SecurityAccessEnum.GroupMembers;
newGroup.AllowDelete = SecurityAccessEnum.GroupMembers;
newGroup.AllowModify = SecurityAccessEnum.GroupMembers;
newGroup.GroupNodeGUID = Guid.Empty;

// Saves the group to the database
GroupInfoProvider.SetGroupInfo(newGroup);


> Back to list of examples

Updating a group




// Gets the group
GroupInfo updateGroup = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);
if (updateGroup != null)
{
    // Updates the group properties
    updateGroup.GroupDisplayName = updateGroup.GroupDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    GroupInfoProvider.SetGroupInfo(updateGroup);
}


> Back to list of examples

Updating multiple groups




// Prepares a condition for loading all groups whose name starts with 'NewGroup'
string where = "GroupName LIKE N'NewGroup%'";

// Gets the groups based on the condition
InfoDataSet<GroupInfo> groups = GroupInfoProvider.GetGroups(where, null);

// Loops through the group objects
foreach (GroupInfo group in groups)
{
    // Updates the group properties
    group.GroupDisplayName = group.GroupDisplayName.ToUpper();

    // Saves the changes to the database
    GroupInfoProvider.SetGroupInfo(group);
}


> Back to list of examples

Deleting a group




// Gets the group
GroupInfo deleteGroup = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);

if (deleteGroup != null)
{
    // Deletes the group
    GroupInfoProvider.DeleteGroupInfo(deleteGroup);
}


> Back to list of examples

Group members

Creating a group member




// Gets the group
GroupInfo group = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);

if (group != null)
{
    // Gets the user
    UserInfo user = UserInfoProvider.GetUserInfo("Andy");

    if (user != null)
    {
        // Creates a group member object
        GroupMemberInfo newMember = new GroupMemberInfo();

        // Sets the member properties
        newMember.MemberGroupID = group.GroupID;
        newMember.MemberApprovedByUserID = MembershipContext.CurrentUserProfile.UserID;
        newMember.MemberApprovedWhen = DateTime.Now;
        newMember.MemberInvitedByUserID = MembershipContext.CurrentUserProfile.UserID;
        newMember.MemberUserID = user.UserID;
        newMember.MemberJoined = DateTime.Now;
        newMember.MemberComment = "New member added through the API.";

        // Saves the member to the database
        GroupMemberInfoProvider.SetGroupMemberInfo(newMember);
    }
}


> Back to list of examples

Updating a group member




// Gets the group 
GroupInfo group = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);

if (group != null)
{
    // Gets the user
    UserInfo user = UserInfoProvider.GetUserInfo("Andy");

    if (user != null)
    {
        // Gets the group member matching the user
        GroupMemberInfo updateMember = GroupMemberInfoProvider.GetGroupMemberInfo(user.UserID, group.GroupID);
        if (updateMember != null)
        {
            // Updates the member properties
            updateMember.MemberComment = updateMember.MemberComment.ToLowerCSafe();

            // Saves the changes to the database
            GroupMemberInfoProvider.SetGroupMemberInfo(updateMember);
        }
    }
}


> Back to list of examples

Updating multiple group members




// Gets the group 
GroupInfo group = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);

if (group != null)
{
    // Prepares a condition for loading all members of the specified group
    string where = "MemberGroupID =" + group.GroupID;

    // Gets the group members based on the condition
    InfoDataSet<GroupMemberInfo> members = GroupMemberInfoProvider.GetGroupMembers(where, null);

    // Loops through individual group members
    foreach (GroupMemberInfo member in members)
    {
        // Updates the member properties
        member.MemberComment = member.MemberComment.ToUpper();

        // Saves the changes to the database
        GroupMemberInfoProvider.SetGroupMemberInfo(member);
    }
}


> Back to list of examples

Deleting a group member




// Gets the group 
GroupInfo group = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);

if (group != null)
{
    // Gets the user
    UserInfo user = UserInfoProvider.GetUserInfo("Andy");

    if (user != null)
    {
        // Gets the group member matching the user
        GroupMemberInfo deleteMember = GroupMemberInfoProvider.GetGroupMemberInfo(user.UserID, group.GroupID);

        if (deleteMember != null)
        {
            // Deletes the group member
            GroupMemberInfoProvider.DeleteGroupMemberInfo(deleteMember);
        }
    }
}


> Back to list of examples

Creating an invitation to a group




// Gets the group 
GroupInfo group = GroupInfoProvider.GetGroupInfo("NewGroup", SiteContext.CurrentSiteName);

if (group != null)
{
    // Creates a group invitation 
    InvitationInfo newInvitation = new InvitationInfo();

    // Sets invitation properties
    newInvitation.InvitationComment = "Group invitation created through the API.";
    newInvitation.InvitationGroupID = group.GroupID;
    newInvitation.InvitationUserEmail = "user@localhost.local";
    newInvitation.InvitedByUserID = MembershipContext.AuthenticatedUser.UserID;
    newInvitation.InvitationCreated = DateTime.Now;
    newInvitation.InvitationValidTo = DateTime.Now.AddDays(1);

    // Saves the invitation to the database
    InvitationInfoProvider.SetInvitationInfo(newInvitation);

    // Sends the invitation email
    InvitationInfoProvider.SendInvitationEmail(newInvitation, SiteContext.CurrentSiteName);
}


> Back to list of examples