Ejemplo n.º 1
0
        public async Task EnsureSeedData()
        {
            if (repo.GetAllSearches().Any() == false)
            {
                Search lolCatsSearch = new Search
                {
                    SearchTime = new DateTime(2017, 1, 25, 12, 30, 56),
                    SearchTerm = "lolcats funny"
                };

                repo.AddSearch(lolCatsSearch);

                Search grumpyCatsSearch = new Search
                {
                    SearchTime = new DateTime(2017, 2, 18, 8, 24, 41),
                    SearchTerm = "grumpycats"
                };

                repo.AddSearch(grumpyCatsSearch);

                Search memeSearch = new Search
                {
                    SearchTime = new DateTime(2017, 3, 8, 13, 54, 8),
                    SearchTerm = "funny memes"
                };

                repo.AddSearch(memeSearch);

                await repo.SaveChangesAsync();
            }
        }
        private async Task AddSearchToDb(string term)
        {
            repo.AddSearch(new Search
            {
                SearchTerm = term,
                SearchTime = DateTime.UtcNow
            });

            await repo.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public List <FlightDTO> FindFlights(SearchDTO searchDTO)
        {
            Search search = mapper.Map <Search>(searchDTO);

            Search existingSearch = fr.FindExistingSearch(search);

            if (existingSearch != null)
            {
                List <Flight> flights = fr.RetrieveFlightsFromDb(existingSearch);
                return(mapper.Map <List <FlightDTO> >(flights));
            }

            else
            {
                Response response = fr.GetFlightsFromAmadeus(search);

                JObject flightJObject = JObject.Parse(response.Body);

                List <JToken> results = flightJObject["data"].Children().ToList();

                List <Flight> flights = new List <Flight>();

                foreach (JToken result in results)
                {
                    Flight flight = new Flight()
                    {
                        AirportFrom               = ar.GetAirportByIata(search.AirportFrom.Iata),
                        AirportTo                 = ar.GetAirportByIata(search.AirportTo.Iata),
                        Currency                  = cr.GetCurrencyByCode(search.Currency.Code),
                        DepartureDate             = search.DepartureDate,
                        ReturnDate                = search.ReturnDate,
                        NumOfConnFlightsDeparture = result["offerItems"].First["services"].First["segments"].Count(),
                        NumOfConnFlightsReturn    = result["offerItems"].First["services"].Last["segments"].Count(),
                        NumOfPassengers           = search.NumOfPassengers,
                        Price = (double)result["offerItems"].First["price"]["total"]
                    };

                    flights.Add(flight);
                }

                foreach (Flight flight in flights)
                {
                    flight.Search.Add(search);
                    fr.AddFlight(flight);
                }
                sr.AddSearch(search);

                return(mapper.Map <List <FlightDTO> >(flights));
            }
        }