public void InsertOrUpdate(Category category)
 {
     if (category.CategoryId == default(int)) {
         // New entity
         context.Categories.Add(category);
     } else {
         // Existing entity
         context.Entry(category).State = EntityState.Modified;
     }
 }
 public ActionResult Create(Category category)
 {
     if (ModelState.IsValid) {
         categoryRepository.InsertOrUpdate(category);
         categoryRepository.Save();
         var categories = categoryRepository.GetAll().ToList();
         cache.Put("categories", categories);
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid) {
         categoryRepository.InsertOrUpdate(category);
         categoryRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }