public ActionResult Edit(int id, Product sp, HttpPostedFileBase Image) { // TODO: Add update logic here if (Image != null) { var fileName = Path.GetFileName(Image.FileName); var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName); if (System.IO.File.Exists(path)) { sp.Image = fileName; } else { Image.SaveAs(path); sp.Image = fileName; } } else { ProductBus.UpdateNoImage(id, sp); } var htf = HttpContext.Request.Files; var lstImage = ProductBus.getListImage(id).ToList(); for (int i = 1; i < htf.Count; i++) { if (htf[i].ContentLength > 0) { string fileName = ""; if (Request.Browser.Browser == "IE") { fileName = Path.GetFileName(htf[i].FileName); } else { fileName = htf[i].FileName; } var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName); if (System.IO.File.Exists(path)) { ProductBus.UpdateImage(fileName, lstImage[i - 1].Image_ID); } else { htf[i].SaveAs(path); ProductBus.UpdateImage(fileName, lstImage[i - 1].Image_ID); } } } ProductBus.Update(id, sp); return(RedirectToAction("Index")); }
// GET: QuanLyProduct/Edit/5 public ActionResult Edit(int id) { //if (id == null) //{ // Response.StatusCode = 404; // return null; //} var sp = ProductBus.GetProduct(id); if (sp == null) { HttpNotFound(); } ViewBag.CategogyID = new SelectList(ProductBus.GetListCategogy(), "ID", "CategogyName", sp.CategogyID); ViewBag.ManufacturerID = new SelectList(ProductBus.GetListManufacturer(), "ID", "ManufacturerName", sp.ManufacturerID); ViewBag.ThongBao = ""; ViewBag.ListImage = ProductBus.getListImage(id).ToList(); return(View(sp)); }