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