public ActionResult Edit(FormCollection fc, CMS_Documents obj) { try { if (ModelState.IsValid) { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); if (objDAO.CheckExist_DocumentNumber(obj)) { SetAlert("Số hiệu đã tồn tại!", AlertType.Error); return(View()); } if (objDAO.Update(obj)) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Cập nhật văn bản thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Documents")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public bool Update(CMS_Documents entity) { try { CMS_Documents obj = MyContext.CMS_Documents.Find(entity.ID); obj.DocumentNumber = entity.DocumentNumber; obj.TypeOfDocumentID = entity.TypeOfDocumentID; obj.AreaOfDocument = entity.AreaOfDocument; obj.Abstract = entity.Abstract; obj.Contents = entity.Contents; obj.OrganizationID = entity.OrganizationID; obj.IssuedDate = entity.IssuedDate; obj.EffectiveDate = entity.EffectiveDate; obj.Signer = entity.Signer; obj.FileName = entity.FileName; obj.Publish = entity.Publish == null ? false : entity.Publish; obj.Effective = entity.Effective == null ? false : entity.Effective; obj.Description = entity.Description; MyContext.Entry(obj).State = EntityState.Modified; MyContext.SaveChanges(); return(true); } catch (Exception ex) { Logs.WriteLog(ex); return(false); } }
public int Insert(CMS_Documents entity) { try { entity.CreateDate = System.DateTime.Now; MyContext.CMS_Documents.Add(entity); MyContext.SaveChanges(); return(entity.ID); } catch (Exception ex) { Logs.WriteLog(ex); throw; } }
public ActionResult Create(FormCollection fc, CMS_Documents obj) { try { TempData.Keep("TypeOfDocumentID"); TempData.Keep("AreaOfDocument"); TempData.Keep("OrganizationID"); if (ModelState.IsValid) { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); if (objDAO.CheckExist_DocumentNumber(obj)) { SetAlert("Số hiệu đã tồn tại!", AlertType.Error); return(View()); } CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Thêm văn bản thành công", AlertType.Success); return(RedirectToAction("index", "cms_documents")); } else { ModelState.AddModelError("", "Thêm văn bản không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public bool CheckExist_DocumentNumber(CMS_Documents entity) { try { var obj = MyContext.CMS_Documents.Where(x => x.DocumentNumber.Trim().Contains(entity.DocumentNumber.Trim())).FirstOrDefault(); if (obj != null) { if (entity.ID != obj.ID) { return(true); } return(false); } return(false); } catch (Exception ex) { Logs.WriteLog(ex); return(false); } }