Exemplo n.º 1
0
        public JsonResult SaveFlight(FlightViewModel model)
        {
            var result = false;

            try
            {
                if (ModelState.IsValid)
                {
                    if (model.FlightId > 0)
                    {
                        Flight flight = _flightrepos.GetFlightByID(model.FlightId);
                        flight.FlightDeparture  = model.FlightDeparture;
                        flight.FlightArrival    = model.FlightArrival;
                        flight.DepartureId      = model.DepartureId;
                        flight.ArrivalId        = model.ArrivalId;
                        flight.AircraftId       = model.AircraftId;
                        flight.AirlineId        = model.AirlineId;
                        flight.FlightAirline    = airlines.FirstOrDefault(a => a.Id.Equals(model.AirlineId));
                        flight.ArrivalAirport   = airports.FirstOrDefault(a => a.Id.Equals(model.ArrivalId));
                        flight.DepartureAirport = airports.FirstOrDefault(a => a.Id.Equals(model.DepartureId));
                        flight.Aircraft         = _aircraftRepo.GetAircraftById(model.AircraftId);
                        _flightrepos.EditFlight(flight);
                    }
                    else
                    {
                        Flight flight = new Flight();
                        flight.FlightId         = model.FlightId;
                        flight.FlightDeparture  = model.FlightArrival;
                        flight.DepartureId      = model.DepartureId;
                        flight.ArrivalId        = model.ArrivalId;
                        flight.AircraftId       = model.AircraftId;
                        flight.AirlineId        = model.AirlineId;
                        flight.FlightDeparture  = model.FlightDeparture;
                        flight.FlightArrival    = model.FlightArrival;
                        flight.FlightAirline    = _airlineRepo.GetAirlinecompanyById(model.AirlineId);
                        flight.ArrivalAirport   = _airportRepo.GetAirportById(model.ArrivalId);
                        flight.DepartureAirport = _airportRepo.GetAirportById(model.DepartureId);
                        flight.Aircraft         = _aircraftRepo.GetAircraftById(model.AircraftId);
                        _flightrepos.AddFlight(flight);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result));
        }
        public IActionResult List(int?selectId)
        {
            _logger.LogDebug(string.Concat("List aircraft", selectId.HasValue ? $" (, {selectId} is selected" : string.Empty));

            var viewModel = new AircraftViewModel {
                ExistingAircraft = _aircraftRepository.GetAllAircraft()
            };

            if (selectId.HasValue)
            {
                var editedAircraft = _aircraftRepository.GetAircraftById(selectId.Value);
                viewModel.SelectedAircraft = editedAircraft;
            }

            return(View("Aircraft", viewModel));
        }
Exemplo n.º 3
0
        public IActionResult Submit(FlightViewModel parameter)
        {
            _logger.LogDebug("Submiting flight");

            if (parameter?.SelectedFlight?.Aircraft?.Id == null)
            {
                _logger.LogWarning("Submit flight cancelled: aircraft id is null");
                return(new RedirectToActionResult("List", "Flight", null));
            }
            if (parameter?.SelectedFlight?.FromAirport?.Code == null)
            {
                _logger.LogWarning("Submit flight cancelled: departure airport code is null");
                return(new RedirectToActionResult("List", "Flight", null));
            }
            if (parameter?.SelectedFlight?.ToAirport?.Code == null)
            {
                _logger.LogWarning("Submit flight cancelled: arrival airport code is null");
                return(new RedirectToActionResult("List", "Flight", null));
            }

            parameter.SelectedFlight.Aircraft =
                _aircraftRepository.GetAircraftById(parameter.SelectedFlight.Aircraft.Id);
            parameter.SelectedFlight.FromAirport =
                _airportRepository.GetAirportByCode(parameter.SelectedFlight.FromAirport.Code);
            parameter.SelectedFlight.ToAirport =
                _airportRepository.GetAirportByCode(parameter.SelectedFlight.ToAirport.Code);

            if (_flightRepository.GetFlightById(parameter.SelectedFlight.Id) != null)
            {
                _logger.LogDebug("Flight Id already exist");
                _flightRepository.UpdateFlight(parameter.SelectedFlight);
            }
            else
            {
                _flightRepository.CreateFlight(parameter.SelectedFlight);
            }

            return(new RedirectToActionResult("List", "Flight", null));
        }
Exemplo n.º 4
0
        public IActionResult Report()
        {
            _logger.LogDebug("Report called");

            // todo: remove this test data when using database
            if (_flightRepository.GetAllFlights().Count == 0)
            {
                var fSample = new Flight
                {
                    FromAirport = _airportRepository.GetAirportByCode("LME"),
                    ToAirport   = _airportRepository.GetAirportByCode("CDG"),
                    Aircraft    = _aircraftRepository.GetAircraftById(1)
                };
                _flightRepository.CreateFlight(fSample);
            }

            var viewModel = new ReportViewModel
            {
                Aircraft = _aircraftRepository.GetAllAircraft(),
                Flights  = _flightRepository.GetAllFlights()
            };

            return(View(viewModel));
        }