public ActionResult Create(FormCollection fc, CMS_Notifications obj)
 {
     try
     {
         if (ModelState.IsValid)
         {
             CMS_Notifications_DAO objDAO     = new CMS_Notifications_DAO();
             CSF_Users_DAO         objUserDao = new CSF_Users_DAO();
             int userID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name);
             obj.UserCreate = userID;
             int ReturnID = objDAO.Insert(obj);
             if (ReturnID > 0)
             {
                 //cache lai thong bao
                 WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController();
                 hController.Cache_ThongBao();
                 SetAlert("Thêm thông báo nội bộ thành công", AlertType.Success);
                 return(RedirectToAction("Index", "CMS_Notifications"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm thông báo nội bộ 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 ActionResult Edit(FormCollection fc, CMS_Notifications obj)
 {
     try
     {
         if (ModelState.IsValid)
         {
             CMS_Notifications_DAO objDAO = new CMS_Notifications_DAO();
             if (objDAO.Update(obj))
             {
                 //cache lai thong bao
                 WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController();
                 hController.Cache_ThongBao();
                 SetAlert("Cập nhật thông báo nội bộ thành công", AlertType.Success);
                 return(RedirectToAction("Index", "CMS_Notifications"));
             }
             else
             {
                 SetAlert("Cập nhật thông báo nội bộ 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());
     }
 }
Esempio n. 3
0
 public int Insert(CMS_Notifications entity)
 {
     try
     {
         entity.CreateDate = System.DateTime.Now;
         MyContext.CMS_Notifications.Add(entity);
         MyContext.SaveChanges();
         return(entity.ID);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         throw;
     }
 }
Esempio n. 4
0
 public bool Update(CMS_Notifications entity)
 {
     try
     {
         CMS_Notifications obj = MyContext.CMS_Notifications.Find(entity.ID);
         obj.Title    = entity.Title;
         obj.Contents = entity.Contents;
         obj.Publish  = entity.Publish;
         MyContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return(false);
     }
 }