// GET: Categories/Details/5 public ActionResult Details(int id) { CategoriesHelper categoryHelper = new CategoriesHelper(); Category category = categoryHelper.FindById(id); CategoriesEditViewModel model = new CategoriesEditViewModel() { Name = category.Name }; return View(model); }
// GET: Categories/Edit/5 public ActionResult Edit(int id) { if (id > 0) { CategoriesHelper categoryHelper = new CategoriesHelper(); Category category = categoryHelper.FindById(id); CategoriesEditViewModel model = new CategoriesEditViewModel() { Id = id, Name = category.Name }; return View(model); } return RedirectToAction("Index"); }
public ActionResult Edit(int id, CategoriesEditViewModel model) { try { // TODO: Add update logic here if (ModelState.IsValid) { CategoriesHelper categoryHelper = new CategoriesHelper(); Category category = categoryHelper.FindById(id); category.Name = model.Name.Trim(); categoryHelper.Update(category); return RedirectToAction("Index"); } return View(model); } catch { return View(); } }