Beispiel #1
0
        public async Task <IActionResult> AddFlight()
        {
            FlightToAddViewModel flightToAddViewModel = new FlightToAddViewModel();

            flightToAddViewModel.AirCrafts = await _aircraftBL.GetAircraftsBL();

            return(View(flightToAddViewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> AddFlight(FlightToAddViewModel flightToAddViewModel, CancellationToken token)
        {
            AirPortBE  departureAirport = new AirPortBE();
            AirPortBE  arrivalAirport   = new AirPortBE();
            AirCraftBE aircraftUsed     = new AirCraftBE();

            FlightBE flightToAdd = new FlightBE();

            string idCurrentUserString;
            double distanceTrip;
            double tripfuelConsumption;

            idCurrentUserString = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            departureAirport    = await _airportBL.GetAirportByCodeBL(flightToAddViewModel.CodeFlightDeparture);

            arrivalAirport = await _airportBL.GetAirportByCodeBL(flightToAddViewModel.CodeFlightArrival);

            aircraftUsed = await _aircraftBL.GetAircraftByIdBL(flightToAddViewModel.FkAirCraft);

            /* We are calculating the distance between two airports using the latitude/longitude of those points */
            distanceTrip = distance(double.Parse(departureAirport.Latitude, System.Globalization.CultureInfo.InvariantCulture), double.Parse(departureAirport.Longitude), double.Parse(arrivalAirport.Latitude), double.Parse(arrivalAirport.Longitude), 'K');

            /* We have the information of the consumption of each aircraft in Kilogram by 1000KM in the database,
             *              so we are doing a simple rule of three to have the consomation for the distance traveled,
             *              in addition to that we add the additional fuel consumption during the takeoff for each aircraft */
            tripfuelConsumption = ((aircraftUsed.FuelConsumption * distanceTrip) / 1000) + (double)aircraftUsed.FuelConsumptionTakeoff;

            flightToAdd.FkDeparture         = departureAirport.Id;
            flightToAdd.FkArrival           = arrivalAirport.Id;
            flightToAdd.FkUser              = idCurrentUserString;
            flightToAdd.FkAirCraft          = aircraftUsed.Id;
            flightToAdd.Distance            = distanceTrip;
            flightToAdd.TripFuelConsumption = tripfuelConsumption;
            flightToAdd.DistanceUnit        = "KM"; // To put in a config file

            await _flightBL.AddFlightBL(flightToAdd, token);

            return(RedirectToAction("AllFlights", "Flight"));
        }