Exemplo n.º 1
0
 public async static Task <FlightOfferSearch> ReadByUrl(string reqUrl)
 {
     using (AirlineTicketsDBEntities db = new AirlineTicketsDBEntities())
     {
         FlightOfferSearch fos = db.FlightOfferSearches.Where(f => f.URLQuery == reqUrl)
                                 .Include(f => f.Airport)
                                 .Include(f => f.Airport1)
                                 .Include(f => f.FlightOfferResults)
                                 .Include(f => f.FlightOfferResults.Select(s => s.FlightsForOffers))
                                 .Include(f => f.FlightOfferResults.Select(ffo => ffo.FlightsForOffers.Select(fl => fl.Flights)))
                                 .Include(f => f.FlightOfferResults.Select(ffo => ffo.FlightsForOffers.Select(fl => fl.Flights.Select(a => a.Airport))))
                                 .Include(f => f.FlightOfferResults.Select(ffo => ffo.FlightsForOffers.Select(fl => fl.Flights.Select(a => a.Airport1))))
                                 .FirstOrDefault();
         //foreach(var fOfferResult in fos.FlightOfferResults)
         //{
         //    foreach(var flightForOffer in fOfferResult.FlightsForOffers)
         //    {
         //        foreach(var flight in flightForOffer.Flights)
         //        {
         //            flight.Airport = await AirportsRepo.ReadById(flight.DepartureAirportId);
         //            flight.Airport1 = await AirportsRepo.ReadById(flight.ArrivalAirportId);
         //        }
         //    }
         //}
         return(fos);
     }
 }
Exemplo n.º 2
0
        public async Task <ActionResult> List(string originalLocationCode, string originalLocation, string destinationLocationCode, string destinationLocation, string departureDate, string returnDate, short?adults, short?children, short?infants, string travelClass, string currencyCode, bool?nonStop, int?page)
        {
            try
            {
                if (String.IsNullOrEmpty(originalLocationCode) || String.IsNullOrEmpty(destinationLocationCode) || String.IsNullOrEmpty(departureDate))
                {
                    return(null);
                }

                int pageSize   = 10;
                int pageNumber = (page ?? 1);

                FlightOfferSearch flightOfferSearch = new FlightOfferSearch();
                flightOfferSearch.CreateOffer(originalLocationCode, destinationLocationCode, departureDate, returnDate, adults, children, infants, travelClass, currencyCode, nonStop);
                FlightOfferSearch search = await FlightOfferSearchesRepo.ReadByUrl(flightOfferSearch.URLQuery);

                if (search == null)
                {
                    int searchId = await AmadeusRepo.PassToDatabase(flightOfferSearch);

                    search = await FlightOfferSearchesRepo.ReadById(searchId);

                    return(PartialView(search.FlightOfferResults.ToPagedList(pageNumber, pageSize)));
                }
                else
                {
                    return(PartialView(search.FlightOfferResults.ToList().ToPagedList(pageNumber, pageSize)));
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
 public async static Task <FlightOfferSearch> ReadById(int id)
 {
     using (AirlineTicketsDBEntities db = new AirlineTicketsDBEntities())
     {
         FlightOfferSearch fos = db.FlightOfferSearches.Where(f => f.Id == id)
                                 .Include(f => f.Airport)
                                 .Include(f => f.Airport1)
                                 .Include(f => f.FlightOfferResults)
                                 .Include(f => f.FlightOfferResults.Select(s => s.FlightsForOffers))
                                 .Include(f => f.FlightOfferResults.Select(or => or.FlightsForOffers.Select(fl => fl.Flights)))
                                 .Include(f => f.FlightOfferResults.Select(ffo => ffo.FlightsForOffers.Select(fl => fl.Flights.Select(a => a.Airport))))
                                 .Include(f => f.FlightOfferResults.Select(ffo => ffo.FlightsForOffers.Select(fl => fl.Flights.Select(a => a.Airport1))))
                                 .FirstOrDefault();
         return(fos);
     }
 }
Exemplo n.º 4
0
        public async static Task <int> Create(FlightOfferSearch fos)
        {
            using (AirlineTicketsDBEntities db = new AirlineTicketsDBEntities())
            {
                try
                {
                    db.FlightOfferSearches.Add(fos);
                    await db.SaveChangesAsync();

                    return(fos.Id);
                }
                catch (Exception ex)
                {
                    throw new Exception("Greška kod spremanja FlightOfferSearch u bazu podataka.");
                }
            }
        }
Exemplo n.º 5
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;
            }
        }