/// <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; }