public ActionResult DetailPostComments(int id = 0) { LstCommentsByPost myLstCommentsByPost = new LstCommentsByPost(); myLstCommentsByPost.postConcerned = db.Posts.Find(id); if (myLstCommentsByPost.postConcerned == null) { return HttpNotFound(); } return View(myLstCommentsByPost); }
public ActionResult DetailPostComments(LstCommentsByPost lstCommentsByPost, int id) { if (ModelState.IsValid) { User userAuthor = db.Users.Find(WebSecurity.CurrentUserId); Post postConcerned = db.Posts.Find(id); Comment newComs = new Comment() { CommentAuthor = userAuthor, CommentContent = lstCommentsByPost.unComment.CommentContent, PostConcerned = postConcerned, DatePublication = DateTime.Today }; db.Comments.Add(newComs); userAuthor.MyLstComment.Add(newComs); postConcerned.Comments.Add(newComs); db.SaveChanges(); return RedirectToAction("DetailPostComments", "Home", new { id = postConcerned.PostId }); } else { return View(lstCommentsByPost); } }