public ActionResult editmanufacturer(manufacture_vm mv) { string path = ""; manufacturer_tbl mt = new manufacturer_tbl(); if (ModelState.IsValid) { mt.brand_name = mv.brand_name; mt.manufacturer_id = mv.manufacturer_id; mt.sort_order = mv.sort_order; if (mv.file != null) { path = Server.MapPath("~/AppFiles/manufacturer/" + mv.logo); if (System.IO.File.Exists(path)) { try { System.IO.File.Delete(path); } catch (Exception e) { //Debug.WriteLine(e.Message); } } string fileName = Path.GetFileNameWithoutExtension(mv.file.FileName); string extension = Path.GetExtension(mv.file.FileName); fileName = "L" + mv.manufacturer_id + extension; fileName = fileName.Replace(" ", "-"); path = fileName; string savePath = Server.MapPath("~/AppFiles/manufacturer/"); mv.file.SaveAs(Path.Combine(savePath, fileName)); mt.logo = path; } else { mt.logo = mv.logo; } db.Entry(mt).State = EntityState.Modified; db.SaveChanges(); message = "ManuFacturer Updated Successfully"; status = true; } else { message = "There Are Some Problems, Try Again"; } TempData["Message"] = message; TempData["Status"] = status; return(RedirectToAction("manufacture")); }
public ActionResult manufacture(manufacture_vm mf) { string path; if (ModelState.IsValid) { manufacturer_tbl mt = new manufacturer_tbl(); mt.brand_name = mf.brand_name; mt.sort_order = mf.sort_order; db.manufacturer_tbl.Add(mt); db.SaveChanges(); var id = db.manufacturer_tbl.Find(mt.manufacturer_id); //save the logo if (mf.file != null) { string fileName = Path.GetFileNameWithoutExtension(mf.file.FileName); string extension = Path.GetExtension(mf.file.FileName); fileName = "L" + id.manufacturer_id + extension; fileName = fileName.Replace(" ", "-"); path = fileName; string savePath = Server.MapPath("~/AppFiles/manufacturer/"); mf.file.SaveAs(Path.Combine(savePath, fileName)); mt.logo = path; db.SaveChanges(); } message = "Menufacture Create Successfully"; status = true; } else { message = "There have Some Problems"; } TempData["Message"] = message; TempData["Status"] = status; return(RedirectToAction("manufacture")); }