public async Task <Grid <UserLikeDto> > getUserLikes(UserLikeParamsDto userLikeParamsDto) { var users = this.context.User.OrderBy(u => u.UserName).AsQueryable(); var userLikes = this.context.UserLike.AsQueryable(); if (userLikeParamsDto.Predicate == "liked") { userLikes = userLikes.Where(ul => ul.SourceUserId == userLikeParamsDto.UserId); users = userLikes.Select(ul => ul.LikedUser); } if (userLikeParamsDto.Predicate == "likedBy") { userLikes = userLikes.Where(ul => ul.LikedUserId == userLikeParamsDto.UserId); users = userLikes.Select(ul => ul.SourceUser); } var result = users.Select(user => new UserLikeDto { UserId = user.Id, Age = user.DateOfBirth.CalculateAge(), City = user.City, Username = user.UserName, KnownAs = user.KnownAs, MainPhotoUrl = user.Photos.FirstOrDefault(p => p.IsMain).Url }); return(await Grid <UserLikeDto> .CreateGridAsync(result, userLikeParamsDto.Page, userLikeParamsDto.Limit)); }
public async Task <ActionResult <Grid <UserLikeDto> > > GetLikes([FromQuery] UserLikeParamsDto userLikeParamsDto) { int userId = this.User.GetUserId(); userLikeParamsDto.UserId = userId; var likes = await this.unitOfWork.UserLikeRepository.getUserLikes(userLikeParamsDto); return(Ok(likes)); }