/// <summary> /// Store selected (unselected) memberships. /// </summary> private void SaveData() { bool saved = false; // Check permission for manage membership if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Membership", "Modify")) { RedirectToAccessDenied("CMS.Membership", "Modify"); } this.lblInfo.Visible = false; // Remove old items string newValues = ValidationHelper.GetString(usMemberships.Value, null); string items = DataHelper.GetNewItemsInList(newValues, currentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { int membershipID = ValidationHelper.GetInteger(item, 0); MembershipRoleInfoProvider.RemoveMembershipFromRole(membershipID, RoleID); MembershipInfoProvider.InvalidateMembershipUsers(membershipID); saved = true; } } } // Add new items items = DataHelper.GetNewItemsInList(currentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to membership foreach (string item in newItems) { int membershipID = ValidationHelper.GetInteger(item, 0); MembershipRoleInfoProvider.AddMembershipToRole(membershipID, RoleID); MembershipInfoProvider.InvalidateMembershipUsers(membershipID); saved = true; } } } if (saved) { usMemberships.Reload(true); lblInfo.Visible = true; } }
/// <summary> /// Adds membership to role. Called when the "Add membership to role" button is pressed. /// </summary> private bool AddMembershipToRole() { // Get role and user objects RoleInfo role = RoleInfoProvider.GetRoleInfo("MyNewRole", CMSContext.CurrentSiteID); MembershipInfo membership = MembershipInfoProvider.GetMembershipInfo("MyNewMembership", CMSContext.CurrentSiteName); if ((role != null) && (membership != null)) { MembershipRoleInfoProvider.AddMembershipToRole(membership.MembershipID, role.RoleID); return(true); } return(false); }