public void Update(string id, FlightOffset carbonOffsetIn)
        {
            FlightOffset currentFlightOffset = Get(id);

            if (currentFlightOffset != null)
            {
                currentFlightOffset.CarbonProjects.AddRange(carbonOffsetIn.CarbonProjects);
                _flightOffsets.ReplaceOne(flightOffset => flightOffset.Id == id, currentFlightOffset);
            }
        }
Example #2
0
        public IActionResult OnPost()
        {
            _departureFlight     = JsonConvert.DeserializeObject <FlightDetails>(Request.Form["departureFlightDetailsJson"]);
            CarbonProjectDetails = JsonConvert.DeserializeObject <CarbonProjectDetails>(Request.Form["submit"]);
            FlightOffset confirmedDepartureFlightOffset = ConfirmFlightOffset(new FlightOffset(_departureFlight, CarbonProjectDetails));

            if (Request.Form.ContainsKey("returnFlightDetailsJson"))
            {
                _returnFlight = JsonConvert.DeserializeObject <FlightDetails>(Request.Form["returnFlightDetailsJson"]);
                FlightOffset confirmedReturnFlightOffset = ConfirmFlightOffset(new FlightOffset(_returnFlight, CarbonProjectDetails));
                return(RedirectToPage("/ThankYou", new
                {
                    DepartureFlightOffsetId = confirmedDepartureFlightOffset.Id,
                    ReturnFlightOffsetId = confirmedReturnFlightOffset.Id
                }));
            }
            return(RedirectToPage("/ThankYou", new { DepartureFlightOffsetId = confirmedDepartureFlightOffset.Id }));
        }
Example #3
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 void Remove(FlightOffset flightOffsetIn) =>
 _flightOffsets.DeleteOne(flightOffset => flightOffset.Id == flightOffsetIn.Id);
 public FlightOffset Create(FlightOffset flightOffset)
 {
     _flightOffsets.InsertOne(flightOffset);
     return(flightOffset);
 }