// GET: Post public ActionResult Index(int postId) { RestoreUser(); IEnumerable <CommentVM> comments = _commentService.GetByPage(PageSize, 1, postId).Select(x => x.ToPLEntity()); int count = _commentService.GetCount(postId); PageVM page = new PageVM { Number = 1, Size = PageSize, TotalItems = count }; CommentPageVM paging = new CommentPageVM { Page = page, Comments = comments }; FullPostVM post = new FullPostVM() { Post = _postService.Get(x => x.Id == postId).ToPLEntity(), Comments = count, Likes = _likeService.GetAll(x => x.PostId == postId).Select(x => x.ToPLEntity()) }; comments = comments.Select(x => { x.UserName = _userService.Get(x.UserId).Name; return(x); }); ViewBag.Owner = _userService.Get(x => x.Id == post.Post.BlogId); ViewBag.Post = post.Post.Id; ViewBag.User = (UserVM)Session["UserInfo"]; ViewBag.FullPost = post; ViewBag.Paging = paging; return(View("Post")); }
public ActionResult GetComments(int postId, int pageNumber = 1) { IEnumerable <CommentVM> comments = _commentService.GetByPage(PageSize, pageNumber, postId).Select(x => x.ToPLEntity()); int count = _commentService.GetCount(postId); PageVM page = new PageVM { Number = pageNumber, Size = PageSize, TotalItems = count }; CommentPageVM paging = new CommentPageVM { Page = page, Comments = comments }; FullPostVM post = new FullPostVM() { Post = _postService.Get(x => x.Id == postId).ToPLEntity(), Comments = count, Likes = _likeService.GetAll(x => x.PostId == postId).Select(x => x.ToPLEntity()) }; comments = comments.Select(x => { x.UserName = _userService.Get(x.UserId).Name; return(x); }); ViewBag.User = (UserVM)Session["UserInfo"]; ViewBag.FullPost = post; ViewBag.Paging = paging; return(PartialView("CommentPartial")); }