public static void InsertImage(MoreImage mi) { using (var db = new ShopSmartPhoneConnectionDB()) { db.Insert(mi); } }
public ActionResult Create(Product sp, HttpPostedFileBase[] Images) { //Kiểm tra hình ảnh if (Images[0] != null) { var fileName = Path.GetFileName(Images[0].FileName); var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName); if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hinh đã tồn tại"; return(View()); } else { Images[0].SaveAs(path); sp.Image = fileName; } } ProductBus.Insert(sp); var id = ProductBus.getIDProductNew(); foreach (var Image in Images) { if (Image != null) { var fileName = Path.GetFileName(Image.FileName); var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName); if (System.IO.File.Exists(path) && fileName != sp.Image) { ViewBag.ThongBao = "Hinh đã tồn tại"; ViewBag.CategogyID = new SelectList(ProductBus.GetListCategogy(), "ID", "CategogyName"); ViewBag.ManufacturerID = new SelectList(ProductBus.GetListManufacturer(), "ID", "ManufacturerName"); return(View()); } else { MoreImage mi = new MoreImage(); Image.SaveAs(path); mi.ImageName = fileName; mi.Product_ID = id; ProductBus.InsertImage(mi); } } } return(RedirectToAction("CreateSpecification")); }