Example #1
0
        private FlightOffset ConfirmFlightOffset(FlightOffset confirmFlightOffset)
        {
            FlightOffset flightOffset = _carbonFlightOffsetService.Get(confirmFlightOffset.FlightDetails);

            if (flightOffset == null)
            {
                _carbonFlightOffsetService.Create(confirmFlightOffset);
                flightOffset = _carbonFlightOffsetService.Get(confirmFlightOffset.FlightDetails);
            }
            else
            {
                if ((_commonService.GetAircrafts()[confirmFlightOffset.FlightDetails.AircraftName].Total - flightOffset.FlightDetails.CurrentCapacity - confirmFlightOffset.FlightDetails.CurrentCapacity) > 0)
                {
                    flightOffset.FlightDetails.CurrentCapacity       += confirmFlightOffset.FlightDetails.CurrentCapacity;
                    flightOffset.FlightDetails.CurrentCarbonEmission += confirmFlightOffset.FlightDetails.CurrentCarbonEmission;
                    _carbonFlightOffsetService.Update(flightOffset.Id, flightOffset);
                }
            }

            return(flightOffset);
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (String.IsNullOrEmpty(DepartureFlightOffsetId))
            {
                return(RedirectToPage("/Index"));
            }

            Airports = await _siaDestinationApiService.GetAirports();

            DepartureFlightOffset    = _carbonFlightOffsetService.Get(DepartureFlightOffsetId);
            CarbonProjectDetails     = DepartureFlightOffset.CarbonProjects.LastOrDefault <CarbonProjectDetails>();
            ViewData["CarbonOffset"] = DepartureFlightOffset.FlightDetails.CurrentCarbonEmission;
            ViewData["CarbonPrice"]  = DepartureFlightOffset.FlightDetails.CurrentCarbonEmission / 1000 * CarbonProjectDetails.CarbonPrice;

            if (!String.IsNullOrEmpty(ReturnFlightOffsetId))
            {
                ReturnFlightOffset       = _carbonFlightOffsetService.Get(ReturnFlightOffsetId);
                ViewData["CarbonOffset"] = DepartureFlightOffset.FlightDetails.CurrentCarbonEmission + ReturnFlightOffset.FlightDetails.CurrentCarbonEmission;
                ViewData["CarbonPrice"]  = (DepartureFlightOffset.FlightDetails.CurrentCarbonEmission + ReturnFlightOffset.FlightDetails.CurrentCarbonEmission) / 1000 * CarbonProjectDetails.CarbonPrice;
            }

            return(Page());
        }
Example #3
0
        public async Task <IActionResult> OnGetAsync()
        {
            Airports = await _siaDestinationApiService.GetAirports();

            if (String.IsNullOrEmpty(Id))
            {
                Flights = _carbonFlightOffsetService.GetAll();
            }
            else
            {
                Flights.Add(_carbonFlightOffsetService.Get(Id));
            }

            return(Page());
        }