public void InsertOrUpdate(Country country) { if (country.ID == default(int)) { // New entity context.Countries.Add(country); } else { // Existing entity context.Entry(country).State = EntityState.Modified; } }
public ActionResult Create(Country country) { if (ModelState.IsValid) { countryRepository.InsertOrUpdate(country); countryRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }