public static Response MultipleSlicesToResponse(List<IEnumerable<IInDirectFlight>> slices, Passengers passengers, int maxSolutions) { var response = new Response(); var solutions = new List<Solution>(); const int minimuHoursChangePlane = 1; // Build all possible solutions from for (var i = 0; i < slices.ElementAt(0).Count(); i++) { for (var y = 0; y < slices.ElementAt(1).Count(); y++) { var inDirectFlightSlice1 = slices[0].ElementAt(i).Flights.Last(); var inDirectFlightSlice2 = slices[1].ElementAt(y).Flights.First(); if (inDirectFlightSlice1.Date. AddHours(minimuHoursChangePlane). AddMinutes(inDirectFlightSlice1.Route.Duration) >= inDirectFlightSlice2.Date) continue; var tempSolution = new Solution(); tempSolution.InDirectFlights.Add(slices[0].ElementAt(i)); tempSolution.InDirectFlights.Add(slices[1].ElementAt(y)); solutions.Add(tempSolution); } } // Sort solutons by price solutions = solutions.OrderBy(s => s.TotalBasePrice).ToList(); // Cut to maximum number of solutions if (solutions.Count > maxSolutions) solutions.RemoveRange(maxSolutions, solutions.Count - maxSolutions); //solutions.ForEach(Console.WriteLine); // Add data to Response AddDistinctDataValues(solutions, response); // Add TripOption's to Response AddTripOption(solutions, passengers, response); return response; }
public TripOptionViewModels(Response response) : this() { foreach (var tripOption in response.Trips.TripOption) { TripOptionViewModel tripOptionViewModel = new TripOptionViewModel(); tripOptionViewModel.FullPrice = tripOption.SaleTotal; foreach (var slice in tripOption.Slice) { FlightViewModel flight = new FlightViewModel(); var firstSegment = slice.Segment.First(); var lastSegment = slice.Segment.Last(); flight.Departure = firstSegment.Leg[0].Origin; flight.Arrival = lastSegment.Leg[0].Destination; flight.DepartureDate = DateTime.Parse(firstSegment.Leg[0].DepartureTime); flight.ArrivalDate = DateTime.Parse(lastSegment.Leg[0].DepartureTime); tripOptionViewModel.FlightViewModels.FlightViewModelCollection.Add(flight); } TripOptionViewModelCollection.Add(tripOptionViewModel); } }
private static void AddTripOption( ICollection<Solution> solutions, Passengers passengers, Response response) { // Add TriOption to Response response.Trips.TripOption = new List<TripOption>(); // Add Slices to Response AddSlicesToResponse(solutions, response); // Add Pricing information to Response AddPricingsToResponse(solutions, passengers, response); }
private static void AddPricingsToResponse( ICollection<Solution> solutions, Passengers passengers, Response response) { var passengersCount = PassengerHelper.GetPassengerArray(passengers); RouteTaxRepository routeTaxRepository = new RouteTaxRepository(); var tripOptionIndex = 0; // For each solution (Trip Option) foreach (var solution in solutions) { var tempPricings = new List<Pricing>(); decimal totalSolutionFareSale = 0; // For each passenger type for (var i = 0; i < passengersCount.Count; i++) { if (passengersCount[i] == null) continue; // Add pricing information for each passenger type // (For example 2 adults are one pricing info) var tempPricing = new Pricing(); var tempFares = new List<Fare>(); var tempTaxes = new List<Tax>(); var passengerCount = (int)(passengersCount[i]); // Add passengers depending on passenger type switch (i) { case (int)PassengerHelper.PassengerEnum.Adult: tempPricing.Passengers = new Model.QPX.Response.TripOptionModels.Passengers(passengerCount, 0, 0, 0, 0); break; case (int)PassengerHelper.PassengerEnum.Child: tempPricing.Passengers = new Model.QPX.Response.TripOptionModels.Passengers(0, passengerCount, 0, 0, 0); break; case (int)PassengerHelper.PassengerEnum.InfantInLap: tempPricing.Passengers = new Model.QPX.Response.TripOptionModels.Passengers(0, 0, passengerCount, 0, 0); break; case (int)PassengerHelper.PassengerEnum.InfantInSeat: tempPricing.Passengers = new Model.QPX.Response.TripOptionModels.Passengers(0, 0, 0, passengerCount, 0); break; case (int)PassengerHelper.PassengerEnum.Senior: tempPricing.Passengers = new Model.QPX.Response.TripOptionModels.Passengers(0, 0, 0, 0, passengerCount); break; } decimal saleTaxTotal = 0; decimal saleFareTotal = 0; foreach (var slice in solution.InDirectFlights) { // For each flight in one slice foreach (var flight in slice.Flights) { // Add fare depending on flight tempFares.Add(FareHelper.CreateFareFrom(flight)); // For each flight add all corresponding taxes depending on flight route foreach (var routeTax in routeTaxRepository.GetRouteTaxes(flight)) { tempTaxes.Add(RouteTaxConverter.ToTripTax(routeTax, flight)); saleTaxTotal += TaxHelper.GetPrice(flight, routeTax.Tax); } } saleFareTotal += slice.TotalBasePrice; } // Add fares tempPricing.Fare = tempFares; // Add taxes tempPricing.Tax = tempTaxes; // Add price informations tempPricing.SaleFareTotal = PriceHelper.CreatePrice(saleFareTotal); tempPricing.SaleTaxTotal = PriceHelper.CreatePrice(saleTaxTotal); tempPricing.SaleTotal = PriceHelper.CreatePrice(saleFareTotal + saleTaxTotal); tempPricings.Add(tempPricing); // Add passenger price to total solution price totalSolutionFareSale += saleFareTotal + saleTaxTotal; } // Add pricings to response response.Trips.TripOption[tripOptionIndex].Pricing = tempPricings; response.Trips.TripOption[tripOptionIndex].SaleTotal = PriceHelper.CreatePrice(totalSolutionFareSale); tripOptionIndex++; } }