public ActionResult Create(CategoryModel category) { if (ModelState.IsValid) { Category newCategory = new Category(); newCategory.Name = category.Name; newCategory.AgeRating = category.AgeRating; this.Data.Categories.Add(newCategory); this.Data.SaveChanges(); return RedirectToAction("Index"); } return View(category); }
// GET: /Administration/Categories/Delete/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Category category = this.Data.Categories.GetById((int)id); if (category == null) { return HttpNotFound(); } CategoryModel model = new CategoryModel { CategoryId = category.CategoryId, Name = category.Name, AgeRating = category.AgeRating }; return View(model); }
public ActionResult Edit(CategoryModel category) { if (ModelState.IsValid) { var editCategory = this.Data.Categories.GetById(category.CategoryId); editCategory.Name = category.Name; editCategory.AgeRating = category.AgeRating; this.Data.Categories.Update(editCategory); this.Data.SaveChanges(); return RedirectToAction("Index"); } return View(category); }