public ActionResult DeleteConfirmed(int id) { tbl_Items tbl_items = db.tbl_Items.Find(id); if (db.tbl_OrderDetail.Where(a => a.ItemID == id).Count() > 0) { ModelState.AddModelError("ItemName", "Sản phẩn này đã được đặt hàng, bạn không thể xóa!"); return(View(tbl_items)); } if (db.tbl_ImportDetail.Where(a => a.ItemID == id).Count() > 0) { ModelState.AddModelError("ItemName", "Sản phẩn này đã được nhập hàng, bạn không thể xóa!"); return(View(tbl_items)); } string FilesPath = ConfigurationManager.AppSettings["ItemImages"]; string full_path = Server.MapPath(FilesPath).Replace("Item", "").Replace("Edit", ""); if (tbl_items.Images + "" != "") { FileUpload.DeleteFile(tbl_items.Images, full_path); } db.tbl_Items.Remove(tbl_items); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddBanner(tbl_SystemContent content, HttpPostedFileBase file) { content.PropertyContent = file.FileName; if (ModelState.IsValid) { if (file != null) { char DirSeparator = System.IO.Path.DirectorySeparatorChar; string FilesPath = "~\\Images"; string full_path = Server.MapPath(FilesPath).Replace("SystemContent", "").Replace("AddBanner", ""); if (content.PropertyContent + "" != "") { FileUpload.DeleteFile(content.PropertyContent, full_path); } content.PropertyContent = FileUpload.UploadFile(file, full_path); } db.Entry(content).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(content)); }
public ActionResult Edit(tbl_Items tbl_items, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { char DirSeparator = System.IO.Path.DirectorySeparatorChar; string FilesPath = ConfigurationManager.AppSettings["ItemImages"]; string full_path = Server.MapPath(FilesPath).Replace("Item", "").Replace("Edit", ""); if (tbl_items.Images + "" != "") { FileUpload.DeleteFile(tbl_items.Images, full_path); } tbl_items.Images = FileUpload.UploadFile(file, full_path); } db.Entry(tbl_items).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ItemGroupID = new SelectList(db.tbl_ItemGroup, "ItemGroupID", "ItemGroupName", tbl_items.ItemGroupID); return(View(tbl_items)); }