public ActionResult Create(HttpPostedFileBase postedFile, ProductModel model) { if (ModelState.IsValid) { if (postedFile != null) { var filename = "img_" + model.Product.Denumire.ToLower() + ".png"; var path = Path.Combine(Server.MapPath("~/Content/ProductsImages/"), filename); postedFile.SaveAs(path); model.Product.Imagine = "img_" + model.Product.Denumire.ToLower(); } ProductsContainer.SaveProduct(model.Product); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(HttpPostedFileBase postedFile, ProductModel model) { if (ModelState.IsValid) { if (postedFile != null) { var filename = "img_" + model.Product.Denumire.ToLower().Replace(' ', '_') + ".png"; var path = Path.Combine(Server.MapPath("~/Content/ProductsImages/"), filename); postedFile.SaveAs(path); model.Product.Imagine = "img_" + model.Product.Denumire.ToLower().Replace(' ', '_'); } if (model.Product.Pret > 0 && model.Product.Cantitate > 0) { ProductsContainer.SaveProduct(model.Product); return(RedirectToAction("Index")); } } model.Categories = CategoryContainer.GetCategories(); model.Markets = MarketContainer.GetMarkets(); return(View(model)); }