public ActionResult Edit(CategoryModel category) { try { _categoryDataAccess.UpdateCategory(category); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(CategoryModel category) { try { _categoryDataAccess.AddCategory(category); return RedirectToAction("Index"); } catch { return View(); } }
public void UpdateCategory(CategoryModel category) { using (var db = new EventSignInEntities()) { var dbCategory = db.Categories.FirstOrDefault(c => c.Id == category.Id); if (dbCategory == null) { throw new InvalidOperationException(string.Format("Could not find Category with ID: {0}", category.Id)); } dbCategory.Name = category.Name; dbCategory.Description = category.Description; db.SaveChanges(); } }
public int AddCategory(CategoryModel category) { using (var db = new EventSignInEntities()) { var newCategory = new Category { Name = category.Name, Description = category.Description }; db.Categories.Add(newCategory); db.SaveChanges(); return newCategory.Id; } }