public ActionResult Slider_delete(Model_Message model) { Tbl_Slider _Slider = db.Tbl_Slider.Where(a => a.Slider_ID == model.ID).SingleOrDefault(); FileManagement fileManagement = new FileManagement(); string path = Path.Combine(Server.MapPath("~/App_Data/"), _Slider.Tbl_Document.Document_FolderName + "\\" + _Slider.Tbl_Document.Document_Path); fileManagement.DeleteFileWithPath(path); db.Tbl_Document.Remove(_Slider.Tbl_Document); db.Tbl_Slider.Remove(_Slider); if (Convert.ToBoolean(db.SaveChanges() > 0)) { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام شد"; return(RedirectToAction("Slider_List")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام نشد"; return(RedirectToAction("Slider_List")); } }
public ActionResult Slider_Add(Model_SliderAdd model) { if (model.Document != null && model.Document.ContentLength > 0) { Tbl_Document _Document = new Tbl_Document(); Tbl_Slider _Slider = new Tbl_Slider(); Tbl_Login _Login = db.Tbl_Login.Where(a => a.Login_Email == User.Identity.Name || a.Login_Mobile == User.Identity.Name).FirstOrDefault(); _Slider.Slider_Tital = model.Tital; _Slider.Slider_Guid = Guid.NewGuid(); _Slider.Slider_Subject = model.Subject; _Slider.Slider_Link = model.Link; _Slider.Slider_Description = model.Description; _Slider.Slider_IsActive = model.IsActive; _Slider.Slider_CreateDate = DateTime.Now; _Slider.Tbl_Login = _Login; _Document.Document_FileName = model.Document.FileName; _Document.Document_FolderName = "Slider"; _Document.Document_TypeCodeID = 5; _Document.Tbl_Login = _Login; _Document.Document_CreateDate = DateTime.Now; _Document.Document_Guid = Guid.NewGuid(); _Document.Document_Path = Guid.NewGuid().ToString(); model.Document.SaveAs(Path.Combine(Server.MapPath("~/App_Data/Slider/"), _Document.Document_Path)); db.Tbl_Document.Add(_Document); _Slider.Tbl_Document = _Document; db.Tbl_Slider.Add(_Slider); if (Convert.ToBoolean(db.SaveChanges() > 0)) { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام شد"; return(RedirectToAction("Slider_List")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام نشد"; return(RedirectToAction("Slider_List")); } } return(View()); }