public ActionResult Insert(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("~/images/suppliers/" + model.Logo)); //} var from = Server.MapPath("~/photos/"+model.Logo); model.Logo = model.Id + model.Logo.Substring(model.Logo.LastIndexOf(".")); var to = Server.MapPath("~/images/suppliers/" + model.Logo); System.IO.File.Move(from, to); db.Suppliers.Add(model); db.SaveChanges(); ModelState.AddModelError("", "Inserted"); } catch { ModelState.AddModelError("", "Error"); } ViewBag.Suppliers = db.Suppliers; 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("~/images/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); }