public ActionResult Create(BlogModel model) { if (ModelState.IsValid){ using (var dbContext= new BlogDbContext()){ var entity = model.MapFrom<BlogModel, Blog>(); dbContext.Blogs.Add(entity); dbContext.SaveChanges(); return RedirectToAction("Index"); } } return View(model); }
public ActionResult Edit(int id, BlogModel model) { if (ModelState.IsValid) { using (var dbContext = new BlogDbContext()){ var entity = dbContext.Blogs.Single(bm => bm.Id == id); model.MapTo(entity); dbContext.SaveChanges(); return RedirectToAction("Index"); } } return View(model); }