public ActionResult PublishComment(NewComment c) { if (ModelState.IsValid) { Comment comment = new Comment(); Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey; UserInfo userInfo = _db.UserInfo.Single(ui => ui.UserGuid == userGuid); comment.Author = userInfo; comment.Post = _db.Posts.Find(c.PostId); comment.Text = c.Text; comment.PostDate = DateTime.Now; _db.Comments.Add(comment); _db.SaveChanges(); } Post post = _db.Posts.Find(c.PostId); NewComment newComment = new NewComment(); newComment.PostId = post.PostId; newComment.Address = post.Blog.Address; DisComments disComments = new DisComments(); disComments.NewComment = newComment; disComments.Comments = post.Comments.OrderByDescending(x => x.PostDate).Take(5); return PartialView("_Comments", disComments); }
public PartialViewResult PostComments(int id) { Post post = _db.Posts.Find(id); NewComment comment = new NewComment(); comment.PostId = post.PostId; comment.Address = post.Blog.Address; DisComments disComments = new DisComments(); disComments.NewComment = comment; disComments.Comments = post.Comments.OrderByDescending(c => c.PostDate).Take(5); return PartialView("_Comments", disComments); }