Exemplo n.º 1
0
        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)));
        }
Exemplo n.º 2
0
        public async Task CreateFlightAsync(FlightCreateInputModel model)
        {
            var flight = this.mapper.Map <Flight>(model);

            await this.dbContext.Flights.AddAsync(flight);

            await this.dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create()
        {
            var model = new FlightCreateInputModel
            {
                Aircrafts = await this.aircraftsService.GetAllAircraftsAsDropdownListAsync(),
                Airports  = await this.airportsService.GetAllAirportsAsDropdownListAsync()
            };

            return(View(model));
        }