public async Task <CountryEditInputModel> GetCountryEditData(string id) { var country = await this.dbContext.Countries.FindAsync(id); if (country == null) { throw new NullReferenceException("Selected country does not exisit"); } var model = new CountryEditInputModel { Id = country.Id, NewName = country.Name, CurrentName = country.Name }; return(model); }
public async Task <ActionResult> Edit(CountryEditInputModel model) { bool isExisits = await this.countriesService.IsCountryExistsAsync(model.NewName); if (isExisits) { this.ModelState.AddModelError("NewName", "Provided country name already exists"); } if (!this.ModelState.IsValid) { return(this.View(model)); } await this.countriesService.UpdateCountryAsync(model.Id, model.NewName); return(RedirectToAction(nameof(Index))); }