public ActionResult Edit(int id, BlogEntryModel model) { if (ModelState.IsValid){ using (var dbContext = new BlogDbContext()){ var blogEntry = dbContext.BlogEntries.Single(be => be.Id == id); model.MapTo(blogEntry); dbContext.SaveChanges(); } return RedirectToShow(model); } return View(model); }
public ActionResult Create(int id, BlogEntryModel model) { if (ModelState.IsValid){ using (var dbContext = new BlogDbContext()){ var blog = dbContext.Blogs.Single(b => b.Id == id); var blogEntry = new BlogEntry(); blogEntry.Author = GetCurrentWebUser(dbContext); model.MapTo(blogEntry); blog.BlogEntries.Add(blogEntry); dbContext.SaveChanges(); } return RedirectToAction("Details", "Blog", new {id = id}); } return View(model); }