private CommentMapping parseCommentToModel(Comment c) { CommentMapping cMapping = new CommentMapping(); cMapping.id = c.id; cMapping.detail = c.detail; cMapping.createdDate = c.createdDate.GetValueOrDefault().ToString("s"); cMapping.username = c.User.Username; cMapping.fullName = c.User.Fullname; cMapping.userProfile = c.User.ProfileImage; cMapping.userId = c.userId.GetValueOrDefault(); return(cMapping); }
public ActionResult getCommentsForPost(int postId, int lastId) { MessageViewModels response = new MessageViewModels(); object data = null; List <Comment> allComment = null; List <Comment> lastFiveComment = null; Post post = postService.findPostById(postId); if (null == post || post.Status == SLIM_CONFIG.POST_STATUS_HIDE) { response.StatusCode = 2; response.Data = postId; return(Json(response, JsonRequestBehavior.AllowGet)); } if (lastId == 0) { allComment = postService.GetCommentByPostId(postId); lastFiveComment = allComment.Skip(allComment.Count - 5).ToList(); } else { allComment = postService.GetCommentByPostIdHasSmallerId(postId, lastId); lastFiveComment = allComment.Skip(allComment.Count - 5).Reverse().ToList(); } List <CommentMapping> result = new List <CommentMapping>(); long lastGetComment = DateTime.Now.Ticks; foreach (Comment c in lastFiveComment) { CommentMapping cMapping = parseCommentToModel(c); cMapping.lastGetComment = lastGetComment; result.Add(cMapping); } if (result.Count == 0) { data = new { lastGetComment = DateTime.Now.Ticks }; } else { int totalComment = 0; if (lastId == 0) { totalComment = allComment.Count; } data = new { listComment = result, lastGetComment = DateTime.Now.Ticks, totalComment = totalComment }; } response.Data = data; return(Json(response, JsonRequestBehavior.AllowGet)); }
public List <CommentMapping> GetNewComment(int postId, int lastCommentId) { List <Comment> allComment = null; if (lastCommentId == 0) { allComment = commentRepository.List.Where(p => postId == p.postId).ToList(); } else { allComment = commentRepository.List.Where(p => postId == p.postId && p.id > lastCommentId).ToList(); } List <CommentMapping> result = new List <CommentMapping>(); foreach (Comment c in allComment) { CommentMapping cMapping = parseCommentToModel(c); result.Add(cMapping); } return(result); }