Beispiel #1
0
        public ActionResult SubmitSearch(FlightIndexVM flightsData)
        {
            // convert origin and destination cities to codes
            DataLayer dl = new DataLayer();

            flightsData.originCode = (from u in dl.locations
                                      where u.city.ToLower() == flightsData.originCity.ToLower()
                                      select u.code).ToList <string>().FirstOrDefault();

            flightsData.desCode = (from u in dl.locations
                                   where u.city.ToLower() == flightsData.desCity.ToLower()
                                   select u.code).ToList <string>().FirstOrDefault();

            // create the api object
            FlightSearch flightSearch = new FlightSearch();

            flightSearch.FillData(flightsData.originCode, flightsData.desCode, flightsData.sdate, flightsData.edate, flightsData.originCountry, flightsData.originCity, flightsData.desCountry, flightsData.desCity);

            // if no results were found (400: bad request)
            if (flightSearch.GetResponse() != "")
            {
                FlightSearchResultsVM newObj = new FlightSearchResultsVM()
                {
                    destinationCity    = flightSearch.GetDestinationCity(),
                    destinationCountry = flightSearch.GetDestinationCountry(),
                    originCity         = flightSearch.GetOriginCity(),
                    originCountry      = flightSearch.GetOriginCountry(),
                    departureDate      = flightsData.sdate,
                    returnDate         = flightsData.edate,
                };
                return(View("SearchResults", newObj));
            }

            // for the google map
            string[] loc       = flightSearch.GetLocation().Split(',');
            double   latitude  = Double.Parse(loc[0]);
            double   longitude = Double.Parse(loc[1]);

            // create object to pass to the view
            FlightSearchResultsVM flightSearchResultsVM = new FlightSearchResultsVM()
            {
                departureDate       = flightSearch.GetDepartureDate(),
                destinationCity     = flightSearch.GetDestinationCity(),
                destinationCodeCity = flightSearch.GetDestinationCodeCity(),
                destinationCountry  = flightSearch.GetDestinationCountry(),
                inbound             = flightSearch.GetInbound(),
                originCity          = flightSearch.GetOriginCity(),
                originCodeCity      = flightSearch.GetOriginCodeCity(),
                originCountry       = flightSearch.GetOriginCountry(),
                outbound            = flightSearch.GetOutbound(),
                price          = flightSearch.GetPrice(),
                returnDate     = flightSearch.GetReturnDate(),
                seatsRemaining = flightSearch.GetSeatsRemaining(),
                airline        = flightSearch.GetAirline(),
                latitude       = latitude,
                longitude      = longitude,
            };

            return(View("SearchResults", flightSearchResultsVM));
        }
Beispiel #2
0
        public ActionResult SubmitSearchGeneral(GeneralIndexVM obj)
        {
            FlightIndexVM flight = new FlightIndexVM()
            {
                desCity       = obj.desCity,
                desCountry    = obj.desCountry,
                originCity    = obj.originCity,
                originCountry = obj.originCountry,
                sdate         = obj.startDate,
                edate         = obj.endDate,
            };

            return(SubmitSearch(flight));
        }
Beispiel #3
0
        private FlightIndexVM LoadCities()
        {
            FlightIndexVM fivm = new FlightIndexVM();
            DataLayer     dl   = new DataLayer();

            fivm.originCountries = (from u in dl.locations
                                    select u.country).ToList <string>().GroupBy(p => p)
                                   .Select(g => g.First()).OrderBy(q => q)
                                   .ToList();

            fivm.originCities = (from u in dl.locations
                                 where u.country == fivm.originCountries.FirstOrDefault()
                                 select u.city).ToList <string>().GroupBy(p => p)
                                .Select(g => g.First()).OrderBy(q => q)
                                .ToList();

            fivm.desCountries = new List <string>(fivm.originCountries);
            fivm.desCities    = new List <string>(fivm.originCities);

            return(fivm);
        }