public ActionResult AddComment(string commentBody, string username, string postId) { Comment comment = new Comment(); Author author = new Author(); author.Name = username; author.EmailAddress = username; comment.Content = commentBody; comment.Author = author; comment.PostId = int.Parse(postId); comment.CreatedDate = DateTime.Now; db.Comments.Add(comment); db.SaveChanges(); if (Request.IsAjaxRequest()) { return Json(new { username = username, commentBody = commentBody, commentDate = comment.CreatedDate.ToString() }); } Post post = new Post(); post = db.Posts.Find(int.Parse(postId)); return View("Details", new { post = post }); }
public ActionResult Create(PostViewModel postVM) { if (ModelState.IsValid) { Post post = new Post(); post.ModifiedDate = post.CreatedDate = DateTime.Now; post.Content = postVM.Content; post.Title = postVM.Title; db.Posts.Add(post); db.SaveChanges(); return RedirectToAction("Index"); } return View(postVM); }
public ActionResult Edit(Post post) { if (ModelState.IsValid) { db.Entry(post).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(post); }