public async Task <GetUserResponse> Handle(GetUserRequest request, CancellationToken cancellationToken) { string currentUserId = httpContextReader.CurrentUserId; var user = await userService.GetUser(request.UserId, currentUserId); var userToReturn = !await rolesService.IsPermitted(currentUserId, RoleName.Admin) ? (UserDtoBase)mapper.Map <UserDto>(user) : mapper.Map <UserAdminDto>(user); if (user != null) { userToReturn = FriendUtils.SetFriendProperties(userToReturn, user, currentUserId); user.SortPosts(); var userGroups = user.Groups.Concat(user.GroupMembers.Where(m => m.IsAccepted).Select(m => m.Group)) .ToList(); GroupUtils.SetGroupMemberParams(userToReturn.Groups.ToList(), userGroups, currentUserId); return(new GetUserResponse { User = userToReturn }); } throw new CrudException("User cannot be loaded"); }
public async Task <GetUsersPaginationResponse> Handle(GetUsersPaginationRequest request, CancellationToken cancellationToken) { string currentUserId = httpContextService.CurrentUserId; request.UserId = currentUserId; var users = await userService.GetUsers(request) as PagedList <Domain.Entities.Auth.User>; httpContextService.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); var usersToReturn = mapper.Map <List <UserDto> >(users); for (int i = 0; i < users.Count; i++) { usersToReturn[i] = (UserDto)FriendUtils.SetFriendProperties(usersToReturn[i], users[i], currentUserId); } return(new GetUsersPaginationResponse { Users = usersToReturn }); }