public async Task <IList <GetPhotoDto> > GetListPhotosByUserId(int userId) { IList <GetPhotoDto> getPhotoDtos = new List <GetPhotoDto>(); var userPhotos = await _photoRepository .GetUserPhoto() .Include(userphoto => userphoto.Photo) .Include(userphoto => userphoto.User) .OrderByDescending(photo => photo) .Where(userPhoto => userPhoto.UserId == userId) .ToListAsync(); foreach (Entities.UserPhoto userPhoto in userPhotos) { var likesPhotoDtos = await _getLikesPhotoBusiness.GetLikesPhotoDtosByUserPhotoId(userPhoto.Id); getPhotoDtos.Add(new GetPhotoDto { UserPhotoId = userPhoto.Id, UserName = userPhoto.User.Name, ImageBytes = userPhoto.Photo.ImageBytes, Title = userPhoto.Photo.Title, UploadDateTime = userPhoto.Photo.UpdateDateTime, UserId = userPhoto.UserId, LikesPhotoDtos = likesPhotoDtos }); } return(getPhotoDtos); }
public async Task <GetUserPhotoInfoDto> GetUserPhotoInfoDtoByPhotoId(int userPhotoId) { var comments = await _getUserPhotoCommentsBusiness .GetCommentDtosByUserPhotoId(userPhotoId); var likes = await _getLikesPhotoBusiness.GetLikesPhotoDtosByUserPhotoId(userPhotoId); var photo = await GetUserPhotoByUserPhotoId(userPhotoId); return(new GetUserPhotoInfoDto { UserPhotoId = photo.Id, UserName = photo.User.Name, UserId = photo.User.Id, PhotoId = photo.PhotoId, ImageBytes = photo.Photo.ImageBytes, Title = photo.Photo.Title, UploadDateTime = photo.Photo.UpdateDateTime, LikesPhotoDtos = likes, Comments = comments }); }