public ActionResult Create(CategoryViewModel model) { try { Category newCategory = new Category(); newCategory.Name = model.Name; ImagesContext.Categories.Add(newCategory); ImagesContext.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(CategoryViewModel model) { Category cat = ImagesContext.Categories.Where(c => c.Name == model.OldName).First(); ImagesContext.Categories.Remove(cat); ImagesContext.SaveChanges(); cat.Name = model.Name; ImagesContext.Categories.Add(cat); ImagesContext.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult Edit(int id) { Category cat = ImagesContext.Categories.Where(c => c.CategoryID == id).First(); CategoryViewModel category = new CategoryViewModel(); category.Name = cat.Name; category.OldName = cat.Name; return PartialView(category); }