public async Task <IActionResult> Create(DestinationViewModel model) { if (ModelState.IsValid) { City city = await _countryRepository.GetCityAsync(model.CityId); Country country = _countryRepository.GetCountryAsync(city); User user = await _userHelper.GetUserByEmailAsync(User.Identity.Name); Destination destination = new Destination() { Airport = model.Airport, IATA = model.IATA, City = city, Country = country, User = user, }; try { await _repository.CreateAsync(destination); // Ao usar o create grava logo return(RedirectToAction(nameof(Index))); //Redirecionamento para a página // nameof(Index) é o mesmo que colocar ("Index") } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { model.CityId = 0; model.CountryId = 0; model.Cities = _countryRepository.GetComboCities(0); model.Countries = _countryRepository.GetComboCountries(); ModelState.AddModelError(string.Empty, "Already exists a destination with that IATA"); return(View(model)); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); model.Cities = _countryRepository.GetComboCities(0); model.Countries = _countryRepository.GetComboCountries(); return(View(model)); } } } return(View(model)); }