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