Пример #1
0
        public async static Task <bool> DeleteAllSearches()
        {
            using (AirlineTicketsDBEntities db = new AirlineTicketsDBEntities())
            {
                try
                {
                    await FlightsRepo.DeleteAll();

                    await FlightsForOfferRepo.DeleteAll();

                    await FlightOfferResultsRepo.DeleteAll();
                    await DeleteAll();

                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #2
0
        public static async Task <int> PassToDatabase(FlightOfferSearch flightOfferSearch)
        {
            try
            {
                dynamic flightOffers = await AmadeusRepo.GetFlightOffers(flightOfferSearch.URLQuery);

                flightOfferSearch.Id = await FlightOfferSearchesRepo.Create(flightOfferSearch);

                foreach (var flightOffer in flightOffers)
                {
                    FlightOfferResult flightOfferResult = new FlightOfferResult();
                    flightOfferResult.FlightOfferSearchId  = flightOfferSearch.Id;
                    flightOfferResult.PriceForAllTravelers = (decimal)flightOffer.price.total;

                    flightOfferResult.Id = await FlightOfferResultsRepo.Create(flightOfferResult);

                    FlightsForOffer ffoOutgoing = new FlightsForOffer();
                    ffoOutgoing.Duration            = flightOffer.itineraries[0].duration;
                    ffoOutgoing.IsReturnFlight      = false;
                    ffoOutgoing.FlightOfferResultId = flightOfferResult.Id;
                    ffoOutgoing.Id = await FlightsForOfferRepo.Create(ffoOutgoing);

                    int i = 1;
                    foreach (var flightSegment in flightOffer.itineraries[0].segments)
                    {
                        Flight flight = new Flight();
                        flight.DepartureAirportId = await AirportsRepo.ReadByIATA(flightSegment.departure.iataCode.ToString());

                        flight.ArrivalAirportId = await AirportsRepo.ReadByIATA(flightSegment.arrival.iataCode.ToString());

                        flight.DepartureTime    = DateTime.Parse(flightSegment.departure.at.ToString());
                        flight.ArrivalTime      = DateTime.Parse(flightSegment.arrival.at.ToString());
                        flight.Duration         = flightSegment.duration;
                        flight.Order            = short.Parse(i.ToString());
                        flight.FlightForOfferId = ffoOutgoing.Id;
                        await FlightsRepo.Create(flight);

                        i++;
                    }
                    if (flightOffer.itineraries.Count > 1)
                    {
                        FlightsForOffer ffoIncoming = new FlightsForOffer();
                        ffoIncoming.Duration            = flightOffer.itineraries[1].duration;
                        ffoIncoming.IsReturnFlight      = true;
                        ffoIncoming.FlightOfferResultId = flightOfferResult.Id;
                        ffoIncoming.Id = await FlightsForOfferRepo.Create(ffoIncoming);

                        i = 1;
                        foreach (var flightSegment in flightOffer.itineraries[1].segments)
                        {
                            Flight flight = new Flight();
                            flight.DepartureAirportId = await AirportsRepo.ReadByIATA(flightSegment.departure.iataCode.ToString());

                            flight.ArrivalAirportId = await AirportsRepo.ReadByIATA(flightSegment.arrival.iataCode.ToString());

                            flight.DepartureTime    = DateTime.Parse(flightSegment.departure.at.ToString());
                            flight.ArrivalTime      = DateTime.Parse(flightSegment.arrival.at.ToString());
                            flight.Duration         = flightSegment.duration;
                            flight.Order            = short.Parse(i.ToString());
                            flight.FlightForOfferId = ffoIncoming.Id;
                            await FlightsRepo.Create(flight);

                            i++;
                        }
                    }
                }
                return(flightOfferSearch.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }