public ActionResult Create(Category category, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { category.Image = SaveFiles.SaveImageFile(file); } Market.DbContext.Categories.Add(category); try { Market.DbContext.SaveChanges(); } catch { return View("Error"); } return RedirectToAction("Index", "Home"); } return View(category); }
public ActionResult Edit(Category category, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { category.Image = SaveFiles.SaveImageFile(file); } Market.DbContext.Entry(category).State = EntityState.Modified; try { Market.DbContext.SaveChanges(); } catch { return View("Error"); } return RedirectToAction("Index", "Home"); } return View(category); }