public async Task <IActionResult> Create(AirportCreateModel airportCreateModel) { if (ModelState.IsValid) { var foundCountry = _context.Countries.FirstOrDefault(co => co.Name == airportCreateModel.Country); if (foundCountry != null) { Airport newAirport = new Airport { Name = airportCreateModel.Name, ICAO = airportCreateModel.ICAO, IATA = airportCreateModel.IATA, Latitude = airportCreateModel.Latitude, Longitude = airportCreateModel.Longitude, CountryId = foundCountry.Id }; _context.Airports.Add(newAirport); await _context.SaveChangesAsync(); airportCreateModel.Notification = new AlertNotification(NotificationType.Success, $"Successfully added {newAirport.Name}"); return(View(airportCreateModel)); } else { airportCreateModel.Notification = new AlertNotification(NotificationType.Error, "The country entered for this Airport doesn't exist!"); return(View(airportCreateModel)); } } return(View(airportCreateModel)); }
public async Task <IActionResult> Create() { AirportCreateModel viewModel = new AirportCreateModel(); return(View(viewModel)); }