private PagedList <Comment> GetParentCommentsByEntityId(CommentSearchCondition commentSearchCondition) { using (var context = new CommentDbContext()) { var parentCommentQuery = GetComments(context, commentSearchCondition); var parentComments = parentCommentQuery.OrderByDescending(p => p.CreatedOn).ToPagedList(commentSearchCondition.PageNumber, commentSearchCondition.PageSize); FetchAndIncludeReplies(context, parentComments, commentSearchCondition, false); return(parentComments); } }
private static IQueryable <Comment> GetComments(CommentDbContext context, CommentSearchCondition commentSearchCondition) { if (CommonHelpers.IsNotEmptyGuid(commentSearchCondition.ParentId)) { return(context.Comments.Where(x => x.ParentId == commentSearchCondition.ParentId)); } else { return(context.Comments.Where(x => x.PostId == commentSearchCondition.PostId && (x.ParentId == null || x.ParentId == ""))); } }
private static IQueryable<Comment> GetComments(CommentDbContext context, CommentSearchCondition commentSearchCondition) { if (CommonHelpers.IsNotEmptyGuid(commentSearchCondition.ParentId)) { return context.Comments.Where(x => x.ParentId == commentSearchCondition.ParentId); } else { return context.Comments.Where(x => x.PostId == commentSearchCondition.PostId && (x.ParentId == null || x.ParentId == "")); } }
public JsonResult Get(string postId, string parentId, int page, int pageSize) { CommentSearchCondition condition = new CommentSearchCondition() { PostId = postId, ParentId = parentId, PageNumber = page, PageSize = pageSize }; var replies = commentRepository.GetComments(condition); var result = GetExtractedComments(replies, replies.TotalCount); return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult Get(string postId, string parentId, int page, int pageSize) { CommentSearchCondition condition = new CommentSearchCondition() { PostId = postId, ParentId = parentId, PageNumber = page, PageSize = pageSize }; var replies = commentRepository.GetComments(condition); var result = GetExtractedComments(replies, replies.TotalCount); return Json(result, JsonRequestBehavior.AllowGet); }
private void FetchAndIncludeReplies(CommentDbContext dbContext, PagedList <Comment> parentComments, CommentSearchCondition commentSearchCondition, bool fetchCountOnly) { if (parentComments == null || !parentComments.Any()) { return; } var parentCommentIds = parentComments.Select(x => x.Id).ToArray(); var childComments = dbContext.Comments.Where(x => parentCommentIds.Contains(x.ParentId)); foreach (var parent in parentComments) { if (fetchCountOnly) { parent.Replies = childComments.Where(child => child.ParentId == parent.Id).OrderByDescending(p => p.CreatedOn).ToPagedList(true); } else { parent.Replies = childComments.Where(child => child.ParentId == parent.Id).OrderByDescending(p => p.CreatedOn).ToPagedList(commentSearchCondition.PageNumber, commentSearchCondition.PageSize); FetchAndIncludeReplies(dbContext, parent.Replies, commentSearchCondition, true); } } }
public PagedList <Comment> GetComments(CommentSearchCondition searchCondition) { return(GetParentCommentsByEntityId(searchCondition)); }
private void FetchAndIncludeReplies(CommentDbContext dbContext, PagedList<Comment> parentComments, CommentSearchCondition commentSearchCondition, bool fetchCountOnly) { if (parentComments == null || !parentComments.Any()) return; var parentCommentIds = parentComments.Select(x => x.Id).ToArray(); var childComments = dbContext.Comments.Where(x => parentCommentIds.Contains(x.ParentId)); foreach (var parent in parentComments) { if (fetchCountOnly) { parent.Replies = childComments.Where(child => child.ParentId == parent.Id).OrderByDescending(p => p.CreatedOn).ToPagedList(true); } else { parent.Replies = childComments.Where(child => child.ParentId == parent.Id).OrderByDescending(p => p.CreatedOn).ToPagedList(commentSearchCondition.PageNumber, commentSearchCondition.PageSize); FetchAndIncludeReplies(dbContext, parent.Replies, commentSearchCondition, true); } } }
public PagedList<Comment> GetComments(CommentSearchCondition searchCondition) { return GetParentCommentsByEntityId(searchCondition); }
private PagedList<Comment> GetParentCommentsByEntityId(CommentSearchCondition commentSearchCondition) { using (var context = new CommentDbContext()) { var parentCommentQuery = GetComments(context, commentSearchCondition); var parentComments = parentCommentQuery.OrderByDescending(p => p.CreatedOn).ToPagedList(commentSearchCondition.PageNumber, commentSearchCondition.PageSize); FetchAndIncludeReplies(context, parentComments, commentSearchCondition, false); return parentComments; } }