コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }