public int AddCategory(Category category) { using (var context = new EFSportsStoreContext()) { context.Category.Add(category); context.SaveChanges(); }; return category.Id; }
public void SaveCategory(Category category) { if (category.CategoryID == 0) { context.Categories.Add(category); } else { context.Entry(category).State = EntityState.Modified; } context.SaveChanges(); }
public ActionResult EditCategory(Category category) { if (ModelState.IsValid) { repository.SaveCategory(category); TempData["message"] = string.Format("{0} has been saved", category.Name); return RedirectToAction("Categories"); } else { // there is something wrong with the data values return View(category); } }
public bool EditCategory(Category category) { var isUpdated = false; using (var context = new EFSportsStoreContext()) { var existingcategory = GetExistingCategory(category.Id, context); if (existingcategory != null) { existingcategory.Name = category.Name; context.Entry(existingcategory).State = EntityState.Modified; context.SaveChanges(); isUpdated = true; } } return isUpdated; }
public void Update(Category updatedCategory) { Name = updatedCategory.Name; }
public void DeleteCategory(Category category) { context.Categories.Remove(category); context.SaveChanges(); }