public ActionResult Edit(string id, ZipCodeUpdateModel model) { if (ModelState.IsValid) { try { var zipCode = ZipCodesService.GetByZipCode(id); var country = CountriesService.GetCountryByCountryCode(model.CountryCode); var state = StatesService.GetStateByStateId(model.StateId); var city = CitiesService.GetCityByCityId(model.CityId); ZipCodesService.Delete(zipCode); if (country != null && state != null && city != null) { var zip = new ZipCode() { City = city, CityId = model.CityId, CountyCode = model.CountryCode, StateId = model.StateId, Zip = model.Zip, Latitude = model.Latitude, Longitude = model.Longitude }; zip = ZipCodesService.Create(zip); this.FlashInfo(string.Format("Zip {0} was updated successfully", zip.Zip)); return RedirectToAction("Index"); } } catch (ErrorException errorException) { errorException.ToModelState(this); return View(model); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return View(model); } } return RedirectToAction("Index"); }
public ActionResult Edit(string id) { var zipCode = ZipCodesService.GetByZipCode(id); if (zipCode != null) { var model = new ZipCodeUpdateModel(zipCode); return View(model); } return RedirectToAction("Index"); }