public void EditBlog(EditBlogBm bm, int id)
        {
            Blog model = this.Context.Blogs.Find(id);

            model.Title   = bm.Title;
            model.Content = bm.Content;
            this.Context.SaveChanges();
        }
Beispiel #2
0
 public ActionResult Edit(EditBlogBm bm, int id)
 {
     if (!this.ModelState.IsValid)
     {
         return(this.View(bm));
     }
     try
     {
         this.service.EditBlog(bm, id);
         return(RedirectToAction("All"));
     }
     catch (DbEntityValidationException ex)
     {
         var error = ex.EntityValidationErrors.First().ValidationErrors.First();
         this.ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
         EditBlogVm vm = this.service.GetBlogById(id);
         return(this.View(vm));
     }
 }