public ActionResult Create(FormCollection fc, CMS_Photos obj) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); TempData.Keep("TypeOfPhotoID"); if (ModelState.IsValid) { CMS_Photos_DAO objDAO = new CMS_Photos_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 hình ảnh thành công", AlertType.Success); return(RedirectToAction("index", "CMS_Photos")); } 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()); } }
public ActionResult Edit(FormCollection fc, CMS_Photos obj) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); TempData.Keep("TypeOfPhotoID"); if (ModelState.IsValid) { CMS_Photos_DAO objDAO = new CMS_Photos_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_Photos")); } 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 int Insert(CMS_Photos entity) { try { entity.CreateDate = System.DateTime.Now; MyContext.CMS_Photos.Add(entity); MyContext.SaveChanges(); return(entity.ID); } catch (Exception ex) { Logs.WriteLog(ex); throw; } }
public bool Update(CMS_Photos entity) { try { CMS_Photos obj = MyContext.CMS_Photos.Find(entity.ID); obj.Name = entity.Name; obj.TypeOfPhotoID = entity.TypeOfPhotoID; obj.Description = entity.Description; obj.FileName = entity.FileName; obj.Publish = entity.Publish; MyContext.Entry(obj).State = EntityState.Modified; MyContext.SaveChanges(); return(true); } catch (Exception ex) { Logs.WriteLog(ex); return(false); } }