/// <summary> /// Create a new instance of the FlightManager class using the given /// IDataAccess and IFlightPriceCalculator. /// </summary> /// <param name="dataAccess">The IDataAccess for this class to use.</param> /// <param name="flightPriceCalculator">The IFlightPriceCalculator for this class to use.</param> public FlightManager(IDataAccess dataAccess, IFlightPriceCalculator flightPriceCalculator) { _dataAccess = dataAccess; _flightPriceCalculator = flightPriceCalculator; }
/// <summary> /// Convert a Flight object to a PricedFlight object. /// </summary> /// <param name="flight">The flight to convert and price.</param> /// <param name="searchData">The FlightSearchDataModel to be used to help calculate the price of the flight.</param> /// <param name="calculator">The IFlightPriceCalculator to be used to help calculate the price of the flight.</param> /// <returns>An asynchronous task for pricing the flight.</returns> public static async Task <PricedFlight> PriceFlightAsync(this Flight flight, FlightSearchDataModel searchData, IFlightPriceCalculator calculator) { // Create PricedFlight object. var output = new PricedFlight { Flight = flight }; // Put contents of flight and search data into SelectedFlights object // so total price can be calculated. var totalFlight = new SelectedFlights { Outbound = flight, Inbound = null, NumberAdults = searchData.NumberAdults, NumberChildren = searchData.NumberChildren, TravelClass = searchData.TravelClass }; decimal price = await calculator.CalculateTotalPriceAsync(totalFlight); output.TotalPrice = price; return(output); }
public BookingController(IDataAccess dataAccess, IFlightPriceCalculator calculator, IBookingManager bookingManager) { _dataAccess = dataAccess; _calculator = calculator; _bookingManager = bookingManager; }
public SearchController(IDataAccess dataAccess, IFlightManager flightManager, IFlightPriceCalculator priceCalculator) { _dataAccess = dataAccess; _flightManager = flightManager; _priceCalculator = priceCalculator; }
/// <summary> /// Convert this SelectedFlights object to a SelectedFlightsModel. /// </summary> /// <param name="selectedFlights">The SelectedFlights to convert.</param> /// <param name="calculator">The IFlightPriceCalculator to use to calculate flight prices.</param> public static async Task <SelectedFlightsModel> ToSelectedFlightsModel(this SelectedFlights selectedFlights, IFlightPriceCalculator calculator) { // Populate model with number of passengers and travel class. FlightSearchDataModel searchData = new FlightSearchDataModel { NumberAdults = selectedFlights.NumberAdults, NumberChildren = selectedFlights.NumberChildren, TravelClass = selectedFlights.TravelClass }; SelectedFlightsModel output = new SelectedFlightsModel { Outbound = await selectedFlights.Outbound.PriceFlightAsync(searchData, calculator), Inbound = selectedFlights.Inbound is null ? null : await selectedFlights.Inbound.PriceFlightAsync(searchData, calculator), NumberAdults = selectedFlights.NumberAdults, NumberChildren = selectedFlights.NumberChildren, TravelClass = selectedFlights.TravelClass }; output.TotalPrice = output.Outbound.TotalPrice; if (output.IsReturn) { output.TotalPrice += output.Inbound.TotalPrice; } return(output); } }