예제 #1
0
        /// <summary>
        /// Convert a FlightSearchDataModel to a SearchFilterParameters object.
        /// </summary>
        /// <param name="flightSearchDataModel">The FlightSearchDataModel to convert.</param>
        /// <param name="dataAccess">The IDataAccess to use to obtain Airports from Ids.</param>
        /// <returns>An asynchronous task for finding converting the FlightSearchDataModel.</returns>
        public static async Task <SearchFilterParameters> ToSearchFilterParameters(this FlightSearchDataModel flightSearchDataModel, IDataAccess dataAccess)
        {
            // Get Airport objects from database using their Ids.
            Airport originAirport = await dataAccess.FindAirportByIdAsync(flightSearchDataModel.SelectedOriginAirportId.Value);

            Airport destinationAirport = await dataAccess.FindAirportByIdAsync(flightSearchDataModel.SelectedDestinationAirportId.Value);

            // Set inbound date to the value in the model if return flight,
            // otherwise the inbound date is a default DateTime().
            DateTime inboundDate = new DateTime();

            if (flightSearchDataModel.ReturnFlight == true)
            {
                inboundDate = flightSearchDataModel.InboundDate.Value;
            }

            // Map SearchFilterModel to SearchFilterParameters.
            SearchFilterParameters output = new SearchFilterParameters
            {
                OriginAirport      = originAirport,
                DestinationAirport = destinationAirport,
                OutDate            = flightSearchDataModel.OutboundDate,
                InDate             = inboundDate
            };

            return(output);
        }
예제 #2
0
        /// <summary>
        /// Find the outbound flights that match the given filter parameters.
        /// </summary>
        /// <param name="filterParameters">The parameters to filter the flight by.</param>
        /// <returns>An asynchronous task for finding the flights.</returns>
        public virtual async Task <List <Flight> > FindOutboundFlightsAsync(SearchFilterParameters filterParameters)
        {
            Airport  origin      = filterParameters.OriginAirport;
            Airport  destination = filterParameters.DestinationAirport;
            DateTime date        = filterParameters.OutDate;

            // Get flights from database going from origin -> destination on date.
            List <Flight> flights = await _dataAccess.FindFlightsAsync(origin, destination, date);

            return(flights);
        }
예제 #3
0
        /// <summary>
        /// Find the inbound flights that match the given filter parameters.
        /// </summary>
        /// <param name="filterParameters">The parameters to filter the flight by.</param>
        /// <returns>An asynchronous task for finding the flights.</returns>
        public virtual async Task <List <Flight> > FindInboundFlightsAsync(SearchFilterParameters filterParameters)
        {
            if (filterParameters.Return == false)
            {
                // Flight is not a return flight.
                throw new InvalidOperationException("Flight is not a return flight");
            }

            Airport  origin      = filterParameters.OriginAirport;
            Airport  destination = filterParameters.DestinationAirport;
            DateTime date        = filterParameters.InDate;

            // Get flights from database going from destination -> origin on date.
            List <Flight> flights = await _dataAccess.FindFlightsAsync(destination, origin, date);

            return(flights);
        }
 public DummyFormParameterConstructor
 (
     CommandButtonParameters commandButtonParameters,
     FormControlSettingsParameters formControlSettingsParameters,
     FormGroupArraySettingsParameters formGroupArraySettingsParameters,
     FormGroupSettingsParameters formGroupSettingsParameters,
     FormGroupBoxSettingsParameters groupBoxSettingsParameters,
     MultiSelectFormControlSettingsParameters multiSelectFormControlSettingsParameters,
     SearchFilterGroupParameters searchFilterGroupParameters,
     SearchFilterParameters searchFilterParameters,
     ItemFilterGroupParameters itemFilterGroupParameters,
     MemberSourceFilterParameters memberSourceFilterParameters,
     ValueSourceFilterParameters valueSourceFilterParameters,
     FormattedLabelItemParameters formattedLabelItemParameters,
     HyperLinkLabelItemParameters hyperLinkLabelItemParameters,
     LabelItemParameters labelItemParameters,
     HyperLinkSpanItemParameters hyperLinkSpanItemParameters,
     SpanItemParameters spanItemParameters,
     MultiSelectItemBindingParameters multiSelectItemBindingParameters,
     DropDownItemBindingParameters dropDownItemBindingParameters,
     TextItemBindingParameters textItemBindingParameters
 )
 {
 }
예제 #5
0
        /// <summary>
        /// Find the cheapest outbound flight that matches the given parameters.
        /// </summary>
        /// <param name="filterParameters">The SearchFilterParameters to filter the flights by.</param>
        /// <returns>An asynchronous task for finding the flight.</returns>
        public virtual async Task <Flight> FindCheapestOutboundFlightAsync(SearchFilterParameters filterParameters)
        {
            List <Flight> flights = (await FindOutboundFlightsAsync(filterParameters)).ToList();

            return(await FindCheapestFlightAsync(flights));
        }
예제 #6
0
        /// <summary>
        /// Find the cost of the cheapest flights that match the parameters on days
        /// surrounding the date given in the search parameters.
        /// </summary>
        /// <param name="filterParameters">The parameters to filter the flight by.</param>
        /// <param name="searchPeriod">
        /// The number of days forward and backward
        /// in time that should be searched from the given date.
        /// </param>
        /// <returns>An asynchronous task for retrieving a dictionary of dates and prices.</returns>
        public async Task <Dictionary <DateTime, decimal> > FindCheapestPricesOnSimilarDatesAsync(SearchFilterParameters filterParameters, int searchPeriod)
        {
            DateTime middleDate = filterParameters.OutDate;
            Dictionary <DateTime, decimal> output = new Dictionary <DateTime, decimal>();

            for (int i = -searchPeriod; i <= searchPeriod; i++)
            {
                DateTime date = middleDate.AddDays(i);

                filterParameters.OutDate = date;

                Flight cheapestFlight = await FindCheapestOutboundFlightAsync(filterParameters);

                if ((cheapestFlight is null) || (cheapestFlight.DepartureDateTime < DateTime.Now))
                {
                    // No flight on given date or flight departure time is in the past.
                    output.Add(date, -1);
                    continue;
                }

                decimal price = await _flightPriceCalculator.CalculateBasePriceAsync(cheapestFlight);

                output.Add(date, price);
            }

            // Set out date back to original value.
            filterParameters.OutDate = middleDate;

            return(output);
        }