Пример #1
0
 public ActionResult UpdatePost(Posts model)
 {
     using (var ctx = new BlogHealthEntities())
     {
         var post = ctx.Posts.Where(c => c.ID == model.ID).FirstOrDefault();
         if (post == null)
         {
             return(Json(new { result = "0", msg = "Bài viết không tồn tại!" }, JsonRequestBehavior.AllowGet));
         }
         try
         {
             post.Title            = model.Title;
             post.Slug             = model.Slug;
             post.IDCategory       = model.IDCategory;
             post.ShortContent     = model.ShortContent;
             post.Content          = model.Content;
             post.Tag              = model.Tag;
             post.Update           = DateTime.Now;
             ctx.Entry(post).State = System.Data.Entity.EntityState.Modified;
             ctx.SaveChanges();
             return(Json(new { result = "1", msg = "Cập nhật thành công!" }, JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             return(Json(new { result = "0", msg = ex.Message }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Пример #2
0
 public ActionResult UpdateCategories(Categories model)
 {
     using (var ctx = new BlogHealthEntities())
     {
         var cate = ctx.Categories.Where(c => c.ID == model.ID).FirstOrDefault();
         if (cate != null)
         {
             cate.Name             = model.Name;
             cate.Priority         = model.Priority;
             cate.Slug             = model.Slug;
             cate.Color            = model.Color;
             ctx.Entry(cate).State = System.Data.Entity.EntityState.Modified;
             ctx.SaveChanges();
             return(Json("1", JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json("0", JsonRequestBehavior.AllowGet));
         }
     }
 }