public async Task <IActionResult> AddCity(CityViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    await _countryRepository.AddCityAsync(model);

                    return(this.RedirectToAction($"Details/{model.CountryId}"));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There are a record with the same name.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }

            return(this.View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddCity(CityViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                await _countryRepository.AddCityAsync(model);

                return(this.RedirectToAction($"Details/{model.CountryId}"));
            }

            return(this.View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddCity(CityViewModel model)
        {
            if (ModelState.IsValid)
            {
                await countryRepository.AddCityAsync(model);

                return(RedirectToAction($"{nameof(Details)}/{model.CountryId}"));
            }

            return(View(model));
        }