public async Task <ActionResult> GetPostDetails(PostFilterPagination postFilter) { try { var res = await this.post.GetUserPostDetails(postFilter); return(Ok(res)); } catch (Exception ex) { throw ex; } }
public ActionResult GetAllPostDetail(PostFilterPagination postFilter) { try { var postdetails = _UserBLLManager.GetAllPostDetail(postFilter); if (postdetails == null) { return(NotFound()); } return(new JsonResult(postdetails)); } catch (Exception) { return(BadRequest()); } }
/// <summary> /// method for pull post details data. /// </summary> /// <param name="postFilter"></param> /// <returns></returns> public PaginationResponse GetAllPostDetail(PostFilterPagination postFilter) { PaginationResponse paginationResponse = new PaginationResponse(); try { var res = GetUnitOfWorkPost().GetAll().Select(p => new Post() { Comments = p.Comments, NumberOfComments = p.Comments.Count, CreatedBy = p.CreatedBy, CreatedTime = p.CreatedTime, PostContent = p.PostContent, PostID = p.PostID, }).ToList(); foreach (var item in res) { foreach (Comments comment in item.Comments) { Comments comments = GetUnitOfWorkComments().Find(p => comment.CommentsID == p.CommentsID).Select(c => new Comments() { Vote = c.Vote, }).FirstOrDefault(); comment.NumberOfLike = comments.Vote.Count(p => p.CommentsID == comment.CommentsID && p.LikeORDislike == true); comment.NumberOfLike = comments.Vote.Count(p => p.CommentsID == comment.CommentsID && p.LikeORDislike == false); } } postFilter.Pagination.totalItems = res.Count; paginationResponse.Data = res.Skip((postFilter.Pagination.currentPage - 1) * postFilter.Pagination.itemsPerPage) .Take(postFilter.Pagination.itemsPerPage).GroupBy(p => p.PostID).ToList(); paginationResponse.Pagination = postFilter.Pagination; return(paginationResponse); } catch (Exception ex) { throw new Exception(ex.Message); } }
public PaginationResponse GetUserPostDetails(PostFilterPagination postFilter) { PaginationResponse paginationResponse = new PaginationResponse(); List <VMGroupData> lstVMGroupData = new List <VMGroupData>(); VMGroupData vMGroupData = new VMGroupData(); var res = _aspContext.Post.Select(b => new Post() { Comments = b.Comments, NumberOfComments = b.Comments.Count, CreatedBy = b.CreatedBy, CreatedTime = b.CreatedTime, PostContent = b.PostContent, PostID = b.PostID, }).ToList(); foreach (var item in res) { foreach (Comments items in item.Comments) { Comments comments = _aspContext.Comments.Where(p => items.CommentsID == p.CommentsID).Select(b => new Comments() { Vote = b.Vote, }).FirstOrDefault(); items.NumberOfLike = comments.Vote.Count(p => p.CommentsID == items.CommentsID && p.LikeORDislike == true); items.NumberOfLike = comments.Vote.Count(p => p.CommentsID == items.CommentsID && p.LikeORDislike == false); } } postFilter.Pagination.totalItems = res.Count; paginationResponse.Data = res.Skip((postFilter.Pagination.currentPage - 1) * postFilter.Pagination.itemsPerPage) .Take(postFilter.Pagination.itemsPerPage).GroupBy(p => p.PostID).ToList(); paginationResponse.Pagination = postFilter.Pagination; return(paginationResponse); }
public async Task <object> GetUserPostDetails(PostFilterPagination postFilter) { PaginationResponse paginationResponse = new PaginationResponse(); try { List <PostDataVM> lstVMGroupData = new List <PostDataVM>(); PostDataVM vMGroupData = new PostDataVM(); if (string.IsNullOrEmpty(postFilter.postFilter.User)) { var res = await _aspContext.Post.Select(b => new Post() { Comments = b.Comments, NumberOfComments = b.Comments.Count, CreatedBy = b.CreatedBy, CreatedTime = DateTime.UtcNow, PostContent = b.PostContent, PostID = b.PostID, }).ToListAsync(); foreach (var item in res) { foreach (Comments items in item.Comments) { var vote = await _aspContext.LikeOrDisLikes.Where(p => p.CommentsID == items.CommentsID).ToListAsync(); if (vote != null) { items.NumberOfLike = vote.Count(p => p.CommentsID == items.CommentsID && p.LikeORDislike == true); items.NumberOfLike = vote.Count(p => p.CommentsID == items.CommentsID && p.LikeORDislike == false); } } } postFilter.Pagination.totalItems = res.Count; paginationResponse.Data = res.Skip((postFilter.Pagination.currentPage - 1) * postFilter.Pagination.itemsPerPage) .Take(postFilter.Pagination.itemsPerPage).GroupBy(p => p.PostID).ToList(); paginationResponse.Pagination = postFilter.Pagination; } else { var res = await _aspContext.Post.Where(b => b.PostContent.Equals(postFilter.postFilter.User)).Select(b => new Post() { Comments = b.Comments, NumberOfComments = b.Comments.Count, CreatedBy = b.CreatedBy, CreatedTime = DateTime.UtcNow, PostContent = b.PostContent, PostID = b.PostID, }).ToListAsync(); foreach (var item in res) { foreach (Comments items in item.Comments) { var vote = _aspContext.LikeOrDisLikes.Where(p => p.CommentsID == items.CommentsID).ToList(); if (vote != null) { items.NumberOfLike = vote.Count(p => p.CommentsID == items.CommentsID && p.LikeORDislike == true); items.NumberOfLike = vote.Count(p => p.CommentsID == items.CommentsID && p.LikeORDislike == false); } } } postFilter.Pagination.totalItems = res.Count; paginationResponse.Data = res.Skip((postFilter.Pagination.currentPage - 1) * postFilter.Pagination.itemsPerPage) .Take(postFilter.Pagination.itemsPerPage).GroupBy(p => p.PostID).ToList(); paginationResponse.Pagination = postFilter.Pagination; } } catch (Exception ex) { throw; } return(paginationResponse); }
public ActionResult GetPostDetails(PostFilterPagination postFilter) { return(new JsonResult(_user.GetUserPostDetails(postFilter))); }