public async Task <PagedList <LikeDto> > GetUserLikes(LikesParms likesParams) { var users = _context.Users.OrderBy(u => u.UserName).AsQueryable(); var likes = _context.Likes.AsQueryable(); if (likesParams.Predicate == "liked") { likes = likes.Where(like => like.SourceUserId == likesParams.UserId); users = likes.Select(like => like.LikedUser); } if (likesParams.Predicate == "likedBy") { likes = likes.Where(like => like.LikedUserId == likesParams.UserId); users = likes.Select(like => like.SourceUser); } var likedUsers = users.Select(user => new LikeDto { 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 <LikeDto> .CreateAsync(likedUsers, likesParams.PageNumber, likesParams.PageSize)); }
public async Task <ActionResult <IEnumerable <LikeDto> > > GetUserLikes([FromQuery] LikesParms likesParms) { likesParms.UserId = User.GetUserId(); var users = await _unitOfWork.LikesRepository.GetUserLikes(likesParms); Response.AddPaginationHeader(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(users)); }