public void InsertOrUpdate(ProductCategory productcategory) { if (productcategory.ProductCategoryID == default(int)) { // New entity context.ProductCategories.Add(productcategory); } else { // Existing entity context.Entry(productcategory).State = EntityState.Modified; } }
public ActionResult Create(ProductCategory productcategory) { if (ModelState.IsValid) { productcategoryRepository.InsertOrUpdate(productcategory); productcategoryRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }