public ActionResult Create(Comment comment) { ViewBag.Blogs = db.Blogs; if (ModelState.Any(x => x.Key == "ParentBlog.Title")) { ModelState.Remove("ParentBlog.Title"); } if (ModelState.IsValid) { comment.ParentBlog = db.Blogs.Find(comment.ParentBlog.Id); db.Comments.Add(comment); db.SaveChanges(User.Identity.Name); return RedirectToAction("Index"); } return View(comment); }
public ActionResult Edit(Comment comment) { if (ModelState.Any(x => x.Key == "ParentBlog.Title")) { ModelState.Remove("ParentBlog.Title"); } if (ModelState.IsValid) { var c = db.Comments.Find(comment.Id); var b = db.Blogs.Find(comment.ParentBlog.Id); c.ParentBlog = b; c.Text = comment.Text; db.SaveChanges(User.Identity.Name); return RedirectToAction("Index"); } ViewBag.Blogs = db.Blogs; return View(comment); }