public ActionResult Edit(shop.SANPHAM sp1) { string pathValue = Server.MapPath("~/"); var hpt = HttpContext.Request.Files[0]; if (hpt.FileName == null) { Models.SanPhamBus.SanPhamBus.UpdateProduct(sp1, 0); } else { if (HttpContext.Request.Files.Count > 0) { if (hpt.ContentLength > 0) { string temp = hpt.FileName; string RDString = Guid.NewGuid().ToString(); string fullNameImage = "img/" + RDString + temp; hpt.SaveAs(pathValue + fullNameImage); sp1.HinhAnh = fullNameImage; } } Models.SanPhamBus.SanPhamBus.UpdateProduct(sp1, 1); } return(RedirectToAction("List")); }
public ActionResult Create(shop.SANPHAM sp) { string pathValue = Server.MapPath("~/"); var hpt = HttpContext.Request.Files[0]; if (HttpContext.Request.Files.Count > 0) { if (hpt.ContentLength > 0) { string temp = hpt.FileName; string RDString = Guid.NewGuid().ToString(); string fullNameImage = "img/" + RDString + temp; hpt.SaveAs(pathValue + fullNameImage); sp.HinhAnh = fullNameImage; } } Models.SanPhamBus.SanPhamBus.insert(sp); return(RedirectToAction("Create")); }