コード例 #1
0
        public void Edit(InfoUseful model)
        {
            var obj = Find(model.ID);

            obj.Contents     = model.Contents;
            obj.MetaTitle    = model.MetaTitle;
            obj.Description  = model.Description;
            obj.LinkSeo      = model.LinkSeo;
            obj.CreatedBy    = model.CreatedBy;
            obj.ModifiedDate = DateTime.Now;
            obj.Contents     = model.Contents;
            obj.CreatedDate  = model.CreatedDate;
            context.Entry(obj);
            context.SaveChanges();
        }
コード例 #2
0
 public ActionResult Edit(InfoUseful model)
 {
     try
     {
         var obj = infoUsefulRepository.GetAll().FirstOrDefault(x => x.MetaTitle == model.MetaTitle && x.ID != model.ID);
         if (obj != null)
         {
             return(Json(new
             {
                 IsSuccess = false,
                 Message = "Tin tức đã tồn tại",
             }, JsonRequestBehavior.AllowGet));
         }
         if (string.IsNullOrEmpty(model.Contents))
         {
             return(Json(new
             {
                 IsSuccess = true,
                 Message = "Vui lòng thêm nội dung bài viết",
             }, JsonRequestBehavior.AllowGet));
         }
         var page = Session["PAGE"];
         if (page == null)
         {
             page = 1;
         }
         infoUsefulRepository.Edit(model);
         return(Json(new {
             Page = (int)page,
             IsSuccess = true,
             Message = "Cập nhật thành công",
             JsonRequestBehavior.AllowGet
         }));
     }
     catch (Exception)
     {
         return(Json(new { IsSuccess = false, Message = "Cập nhật thất bại", JsonRequestBehavior.AllowGet }));
     }
 }
コード例 #3
0
 public ActionResult Add(InfoUseful model, string close)
 {
     try
     {
         var obj = infoUsefulRepository.GetAll().FirstOrDefault(x => x.MetaTitle == model.MetaTitle);
         if (obj != null)
         {
             return(Json(new
             {
                 IsSuccess = true,
                 Message = "Tên tin tức đã tồn tại",
             }, JsonRequestBehavior.AllowGet));
         }
         if (string.IsNullOrEmpty(model.Contents))
         {
             return(Json(new
             {
                 IsSuccess = false,
                 Message = "Vui lòng thêm nội dung bài viết",
             }, JsonRequestBehavior.AllowGet));
         }
         infoUsefulRepository.Add(model);
         return(Json(new
         {
             Close = close,
             IsSuccess = true,
             Message = "Thêm mới thành công"
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(new
         {
             IsSuccess = false,
             Message = "Thêm mới thất bại"
         }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #4
0
 public void Add(InfoUseful model)
 {
     context.InfoUsefuls.Add(model);
     context.SaveChanges();
 }