public ActionResult Update(Product model) { try { var f = Request.Files["uplLogo"]; if (f != null && f.ContentLength > 0) { model.Image = model.Id + f.FileName.Substring(f.FileName.LastIndexOf(".")); f.SaveAs(Server.MapPath("/Content/img/products/" + model.Image)); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); ModelState.AddModelError("", "Updated"); } catch { ModelState.AddModelError("", "Error"); } ViewBag.Products = db.Products; ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", model.CategoryId); ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Name", model.SupplierId); return(View("Index", model)); }
public ActionResult Update(Supplier model) { try { var f = Request.Files["uplLogo"]; if (f != null && f.ContentLength > 0) { model.Logo = model.Id + f.FileName.Substring(f.FileName.LastIndexOf(".")); f.SaveAs(Server.MapPath("/Content/img/suppliers/" + model.Logo)); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); ModelState.AddModelError("", "Updated"); } catch { ModelState.AddModelError("", "Error"); } ViewBag.Suppliers = db.Suppliers; return(View("Index", model)); }