public ActionResult AddProduct(ProductViewModel model, HttpPostedFileBase photo) { string PhotoName = ""; if (photo.ContentLength > 0 & photo != null) { PhotoName = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; string path = Server.MapPath("~/Upload/" + PhotoName); photo.SaveAs(path); } model.Product.Photo = PhotoName; result.resultint = pr.Insert(model.Product); if (result.resultint.ProcessResult > 0) { return(RedirectToAction("List")); } return(View(model)); }
public ActionResult AddProduct(ProductViewModel model, List <HttpPostedFileBase> photoPaths) { for (int i = 0; i < photoPaths.Count(); i++) { if (photoPaths[i] != null) { string photoName = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; string path = Server.MapPath("~/Upload/Product/" + photoName); Photo p = new Photo(); p.PhotoName = photoName; model.Product.Photos.Add(p); model.Product.IsDelete = false; photoPaths[i].SaveAs(path); } } result.resultint = pr.Insert(model.Product); if (result.resultint.IsSucceded) { return(RedirectToAction("List")); } return(View()); }