public async Task <IActionResult> Create(FlightCreateInputModel model) { bool isFlightExisits = await this.flightsService.IsFlightExistsAsync(model.ReferenceNumber); if (isFlightExisits) { this.ModelState.AddModelError("ReferenceNumber", "Provided flight number already exists"); } if (model.SourceAirportId == model.DestinationAirportId) { this.ModelState.AddModelError("DestinationAirportId", "Source and destination airports must be different"); } if (!this.ModelState.IsValid) { model.Aircrafts = await this.aircraftsService.GetAllAircraftsAsDropdownListAsync(); model.Airports = await this.airportsService.GetAllAirportsAsDropdownListAsync(); return(this.View(model)); } await this.flightsService.CreateFlightAsync(model); return(RedirectToAction(nameof(Index))); }
public async Task CreateFlightAsync(FlightCreateInputModel model) { var flight = this.mapper.Map <Flight>(model); await this.dbContext.Flights.AddAsync(flight); await this.dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Create() { var model = new FlightCreateInputModel { Aircrafts = await this.aircraftsService.GetAllAircraftsAsDropdownListAsync(), Airports = await this.airportsService.GetAllAirportsAsDropdownListAsync() }; return(View(model)); }