public void InsertOrUpdate(Category category) { if (category.Id == default(int)) { // New entity context.Categories.Add(category); } else { // Existing entity context.Entry(category).State = EntityState.Modified; } }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { categoryRepository.InsertOrUpdate(category); categoryRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }