Example #1
0
        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");
        }
Example #2
0
        public async Task <FetchGroupsPaginationResponse> Handle(FetchGroupsPaginationRequest request,
                                                                 CancellationToken cancellationToken)
        {
            string currentUserId = httpContextService.CurrentUserId;

            request.UserId = currentUserId;

            var groups = await groupService.FetchGroups(request);

            var groupsToReturn = mapper.Map <List <GroupListDto> >(groups);

            GroupUtils.SetGroupMemberParams(groupsToReturn, groups as PagedList <Domain.Entities.Group.Group>, currentUserId);

            httpContextService.AddPagination(groups.CurrentPage, groups.PageSize, groups.TotalCount, groups.TotalPages);

            return(new FetchGroupsPaginationResponse {
                Groups = groupsToReturn
            });
        }
Example #3
0
        public async Task <FetchUserGroupsResponse> Handle(FetchUserGroupsRequest request,
                                                           CancellationToken cancellationToken)
        {
            string currentUserId = httpContextReader.CurrentUserId;

            var userGroupsResult = await groupService.FetchUserGroups() ??
                                   throw new CrudException("Fetching user groups failed");

            var ownGroupsToReturn = mapper.Map <List <GroupListDto> >(userGroupsResult.OwnGroups);
            var myGroupsToReturn  = mapper.Map <List <GroupListDto> >(userGroupsResult.MyGroups);

            GroupUtils.SetGroupMemberParams(ownGroupsToReturn, userGroupsResult.OwnGroups, currentUserId);
            GroupUtils.SetGroupMemberParams(myGroupsToReturn, userGroupsResult.MyGroups, currentUserId);

            return(new FetchUserGroupsResponse
            {
                OwnGroups = ownGroupsToReturn,
                MyGroups = myGroupsToReturn
            });
        }