Advertisement
Guest User

Controller for create comments

a guest
Dec 18th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. [HttpPost]
  2.         [ValidateAntiForgeryToken]
  3.         public ActionResult Comment([Bind(Include = "postID, name, message")] int postId, string name, string message)
  4.         {
  5.            
  6.                 using (var database = new BlogDbContext())
  7.                 {
  8.                     Publication publication = database.Publications.Find(postId);
  9.                     Comment comment = new Comment();
  10.  
  11.                     comment.PostID = postId;
  12.                     comment.CreatedDate = DateTime.Now;
  13.                     comment.Name = name;
  14.                     comment.Body = message;
  15.                     comment.Publications = publication;
  16.  
  17.                     database.Comments.Add(comment);
  18.                     database.SaveChanges();
  19.                     return RedirectToAction("ReadPost");
  20.                 }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement