/// <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>
        /// Retrieves a <see cref="User"/> by it's ID.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/></param>
        /// <param name="id">The ID of the <see cref="User"/>.</param>
        /// <returns>Returns the loaded <see cref="User"/>.</returns>
        public User RetrieveUser(IMansionContext context, Guid id)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");

            // create the user
            var user = new User(id);

            // get the repository
            var repository = context.Repository;

            // first, retrieve the user node
            var userNode = RetrieveRoleOwnerNode(context, user, repository);

            // second, retrieve the groups the user is in
            var groupNodes = RetrieveUserGroupNodes(context, userNode, repository);

            // assemble the role select criteria
            var assignedRoleGuidsUser = userNode.Get(context, "assignedRoleGuids", string.Empty).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
            var assignedRoleGuidsGroups = groupNodes.Nodes.SelectMany(group => group.Get(context, "assignedRoleGuids", string.Empty).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries));
            var assignedRoleGuids = assignedRoleGuidsUser.Union(assignedRoleGuidsGroups).Distinct().ToList();

            // retrieve the roles
            var roleNodes = RetrieveRoleNodes(context, assignedRoleGuids, repository);

            // turn the roles nodes into roles
            foreach (var roleNode in roleNodes.Nodes)
                user.Add(MapRole(context, roleNode));

            // return the user
            return user;
        }
        /// <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)}
                                                      });
        }