public void InsertOrUpdate(City city) { if (city.CityID == default(int)) { // New entity context.City.Add(city); } else { // Existing entity context.Entry(city).State = EntityState.Modified; } }
public ActionResult Create(City city) { if (ModelState.IsValid) { cityRepository.InsertOrUpdate(city); cityRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleCountries = countryRepository.All; ViewBag.PossibleStates = stateRepository.All; return View(); } }
public ViewResult Search(City searchCity) { if(searchCity!=null) { } return View("Index",cityRepository.AllIncluding(city => city.Country, city => city.State)); }