/// <summary> /// Adds the <paramref name="user"/> to the <paramref name="group"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="user">The <see cref="User"/> which to add.</param> /// <param name="group">The <see cref="UserGroup"/> to which to add the user.</param> public void AddGroupMembership(IMansionContext context, User user, UserGroup group) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (user == null) throw new ArgumentNullException("user"); if (group == null) throw new ArgumentNullException("group"); // get the repository var repository = context.Repository; // retrieve the required nodes var userNode = RetrieveRoleOwnerNode(context, user, repository); var groupNode = RetrieveRoleOwnerNode(context, group, repository); // update the user group repository.UpdateNode(context, groupNode, new PropertyBag { {"userGuids", string.Join(",", new[] {groupNode.Get(context, "userGuids", string.Empty), userNode.Get<string>(context, "guid")})} }); }
/// <summary> /// Removes the <paramref name="user"/> from the <paramref name="group"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="user">The <see cref="User"/> which to remove.</param> /// <param name="group">The <see cref="UserGroup"/> from which to remove the user.</param> public void RemoveGroupMembership(IMansionContext context, User user, UserGroup group) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (user == null) throw new ArgumentNullException("user"); if (group == null) throw new ArgumentNullException("group"); // get the repository var repository = context.Repository; // retrieve the required nodes var userNode = RetrieveRoleOwnerNode(context, user, repository); var groupNode = RetrieveRoleOwnerNode(context, group, repository); // build the userGuids array var userGuidsList = (groupNode.Get(context, "userGuids", string.Empty).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)).ToList(); userGuidsList.Remove(userNode.Get<string>(context, "guid")); // update the user group repository.UpdateNode(context, groupNode, new PropertyBag { {"userGuids", string.Join(",", userGuidsList)} }); }