Exemplo n.º 1
0
 public ActionResult Create(FormCollection fc, CMS_Videos obj)
 {
     try
     {
         //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home");
         TempData.Keep("TypeOfVideoID");
         if (ModelState.IsValid)
         {
             CMS_Videos_DAO objDAO     = new CMS_Videos_DAO();
             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)
             {
                 SetAlert("Thêm video thành công", AlertType.Success);
                 return(RedirectToAction("index", "CMS_Videos"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm mới 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());
     }
 }
Exemplo n.º 2
0
 public ActionResult Edit(FormCollection fc, CMS_Videos obj)
 {
     try
     {
         //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home");
         TempData.Keep("TypeOfVideoID");
         if (ModelState.IsValid)
         {
             CMS_Videos_DAO objDAO     = new CMS_Videos_DAO();
             CSF_Users_DAO  objUserDao = new CSF_Users_DAO();
             if (objDAO.Update(obj))
             {
                 SetAlert("Cập nhật thành công", AlertType.Success);
                 return(RedirectToAction("Index", "CMS_Videos"));
             }
             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());
     }
 }
Exemplo n.º 3
0
 public int Insert(CMS_Videos entity)
 {
     try
     {
         entity.CreateDate = System.DateTime.Now;
         MyContext.CMS_Videos.Add(entity);
         MyContext.SaveChanges();
         return(entity.ID);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         throw;
     }
 }
Exemplo n.º 4
0
 public bool Update(CMS_Videos entity)
 {
     try
     {
         CMS_Videos obj = MyContext.CMS_Videos.Find(entity.ID);
         obj.Name                   = entity.Name;
         obj.TypeOfVideoID          = entity.TypeOfVideoID;
         obj.Description            = entity.Description;
         obj.FileName               = entity.FileName;
         obj.Publish                = entity.Publish;
         obj.AvatarPicture          = entity.AvatarPicture;
         MyContext.Entry(obj).State = EntityState.Modified;
         MyContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return(false);
     }
 }