Ejemplo n.º 1
0
 private int CountComment(int postId)
 {
     using (DB_CRMContext db = new DB_CRMContext())
     {
         var comments = (from a in db.TblComments
                         where a.PostId == postId
                         select a).Count();
         return(comments);
     }
 }
Ejemplo n.º 2
0
 private int CountVote(int commentId, bool status)
 {
     using (DB_CRMContext db = new DB_CRMContext())
     {
         var votes = (from a in db.TblVotes
                      where a.CommentId == commentId && a.Vote == status
                      select a).Count();
         return(votes);
     }
 }
Ejemplo n.º 3
0
 public Task <List <PostCommentModel> > GetPostComments()
 {
     using (DB_CRMContext db = new DB_CRMContext())
     {
         var postComments = (from a in db.TblPosts.AsEnumerable()
                             join b in db.TblComments on a.PostId equals b.PostId
                             select new PostCommentModel
         {
             PostTitle = a.PostTitle,
             PostId = a.PostId,
             PostCreateBy = a.CreateBy,
             CountComment = CountComment(a.PostId),
             PostCreateDateTime = a.CreateDateTime.ToString("dd/MM/yyyy"),
             CommentId = b.CommentId,
             Comment = b.Comment,
             CommentCreateBy = b.CreateBy,
             DislikeVote = CountVote(b.CommentId, false),
             LikeVote = CountVote(b.CommentId, true),
             CommentCreateDateTime = b.CreateDateTime.ToString("dd/MM/yyyy")
         }).ToList();
         return(Task.FromResult(postComments));
     }
 }