Exemplo n.º 1
0
        public async Task <PagedList <FollowDto> > GetUserFollows(FollowsParams followsParams)
        {
            var users   = _context.Users.OrderBy(u => u.UserName).AsQueryable();
            var follows = _context.Follows.AsQueryable();

            if (followsParams.Predicate == "followed")
            {
                follows = follows.Where(follow => follow.SourceUserId == followsParams.UserId);
                users   = follows.Select(follow => follow.FollowedUser);
            }
            if (followsParams.Predicate == "followedBy")
            {
                follows = follows.Where(follow => follow.FollowedUserId == followsParams.UserId);
                users   = follows.Select(follow => follow.SourceUser);
            }
            var followedUsers = users.Select(user => new FollowDto {
                Username = user.UserName,
                KnownAs  = user.KnownAs,
                Age      = user.DateOfBirth.CalculateAge(),
                PhotoUrl = user.Photos.FirstOrDefault(p => p.IsMain).Url,
                City     = user.City,
                Id       = user.Id
            });

            return(await PagedList <FollowDto> .CreateAsync(followedUsers, followsParams.PageNumber, followsParams.PageSize));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <IEnumerable <FollowDto> > > GetUserFollows([FromQuery] FollowsParams followsParams)
        {
            followsParams.UserId = User.GetUserId();
            var users = await _unitOfWork.FollowsRepository.GetUserFollows(followsParams);

            Response.AddPaginationHeader(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages);
            return(Ok(users));
        }