/// <summary> /// Recorre la consulta asignando fecha subido/compartido, comentarios y numero de likes /// </summary> /// <param name="postListQueryResponses">Query para recorrer</param> /// <returns>Colección tipo PostResponse</returns> private async Task <ICollection <PostResponse> > ProcessPosts(IQueryable <PostListQueryResponse> postListQueryResponses) { ICollection <PostResponse> postResponses = new List <PostResponse>(); ImageUserProfile imageUserProfile = new ImageUserProfile(false); ILikeService likeService = new LikeService(); foreach (var post in postListQueryResponses) { PostResponse postResponse = new PostResponse(); // Post postResponse.IdPost = post.QueryPost.Id; postResponse.IdTypePost = post.QueryPost.IdTypePost; postResponse.Description = post.QueryPost.Description; // El post fue compartido entonces asignamos la fecha del share // Eso en caso de que consultemos los follows, este caso se presenta // cuando se consultas los post desde la pagina Home postResponse.Date = (post.QueryFollow != null) ? post.QueryPost.Date : ((post.QueryShare != null) ? post.QueryShare.Date : post.QueryPost.Date); if (post.QueryPost.PathFile != null) { if (post.QueryPost.IdTypePost.Equals(1)) { postResponse.File = await Image.GetFile(post.QueryPost.PathFile); } else if (post.QueryPost.IdTypePost.Equals(2)) { postResponse.File = await Image.GetFile(post.QueryPost.PathFile); } } // UserOwner postResponse.IdUserOwner = post.QueryUserOwner.Id; postResponse.NameUserOwner = post.QueryUserOwner.NameUser; postResponse.ImageProfileUserOwner = await imageUserProfile.GetImageUser(post.QueryUserOwner.Id, 'S'); // UserShare if (post.QueryShare != null) { postResponse.IdUserShare = post.QueryUserShare.Id; postResponse.NameUserShare = post.QueryUserShare.NameUser; postResponse.ImageProfileUserShare = await imageUserProfile.GetImageUser(post.QueryUserShare.Id, 'S'); postResponse.DateShare = post.QueryShare.Date; } postResponse.LikeUser = (post.QueryLike != null) ? true : false; // Numero de likes de la publicación postResponse.NumberLikes = likeService.GetNumLikes(post.QueryPost.Id); postResponses.Add(postResponse); } return(postResponses); }
/// <summary> /// Se procesa un solo post /// </summary> /// <param name="postListQueryResponse">En este caso ya devolvemos el post ya que se ejecuta la consulta</param> /// <param name="byId">Id del post que quereoms consultar</param> /// <returns></returns> private async Task <PostResponse> ProcessPostById(PostListQueryResponse postListQueryResponse) { try { PostResponse postResponse = new PostResponse(); ImageUserProfile imageUserProfile = new ImageUserProfile(false); ILikeService likeService = new LikeService(); // Post postResponse.IdPost = postListQueryResponse.QueryPost.Id; postResponse.IdTypePost = postListQueryResponse.QueryPost.IdTypePost; postResponse.Description = postListQueryResponse.QueryPost.Description; postResponse.Date = postListQueryResponse.QueryPost.Date; if (postListQueryResponse.QueryPost.PathFile != null) { postResponse.File = await Image.GetFile(postListQueryResponse.QueryPost.PathFile); } // UserOwner postResponse.IdUserOwner = postListQueryResponse.QueryUserOwner.Id; postResponse.NameUserOwner = postListQueryResponse.QueryUserOwner.NameUser; postResponse.ImageProfileUserOwner = await imageUserProfile.GetImageUser(postListQueryResponse.QueryUserOwner.Id, 'S'); postResponse.LikeUser = (postListQueryResponse.QueryLike != null) ? true : false; // Numero de likes de la publicación postResponse.NumberLikes = likeService.GetNumLikes(postListQueryResponse.QueryPost.Id); return(postResponse); } catch (Exception e) { _logger.LogInformation(e.Message); return(null); } }