public void InsertOrUpdate(Product product)
 {
     if (product.Id == default(int)) {
         // New entity
         context.Products.Add(product);
     } else {
         // Existing entity
         context.Entry(product).State = EntityState.Modified;
     }
 }
 public ActionResult Edit(Product product)
 {
   if (ModelState.IsValid)
   {
     _productRepository.InsertOrUpdate(product);
     _productRepository.Save();
     return RedirectToAction("Index");
   }
   else
   {
     ViewBag.PossibleCategories = _categoryRepository.All;
     return View();
   }
 }