Ejemplo n.º 1
0
        public ActionResult SearchFlights(SearchFlightsViewModel model)
        {
            var today = DateTime.Today;

            var search = from f in db.Flight_Detail where f.DepartureDateTime > today select f;

            if (!String.IsNullOrEmpty(model.fromCountry))
            {
                search = search.Where(x => x.DepartureVenue == model.fromCountry);
            }

            if (!String.IsNullOrEmpty(model.toCountry))
            {
                search = search.Where(x => x.DestinationVenue == model.toCountry);
            }

            if (model.departureDate != null && model.departureDate != DateTime.MinValue)
            {
                search = search.Where(x => DbFunctions.TruncateTime(x.DepartureDateTime) == model.departureDate);
            }

            if (model.departureDate == DateTime.MinValue)
            {
                model.departureDate = null;
            }

            model.flightList = search.OrderBy(x => x.DepartureDateTime).ToList();

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult SearchFlights(SearchFlightsViewModel searchFlightsViewModel)
        {
            ResultsViewModel resultsViewModel = new ResultsViewModel();

            //If "SearchParameters" exists get "SearchResults" by "SearchParameters" and show it on view-"Results"
            if (_SearchFlightsLogic.SearchParametersExists(searchFlightsViewModel.SearchParameters))
            {
                resultsViewModel.SearchResults = _SearchFlightsLogic.GetSearchResultsBySearchParameterID(_SearchFlightsLogic.GetSearchParametersByParameters(searchFlightsViewModel.SearchParameters).ID)
                                                 .OrderBy(x => x.Depart)
                                                 .ToPagedList(1, 5);
            }

            //Http request to Amadeus
            List <SearchResults> listOfResults = _SearchFlightsLogic.HttRequestToAmadeusAPI(searchFlightsViewModel.SearchParameters);

            //If there are no results something went wrong (redirect back to SearchFlights view)
            if (listOfResults.Count == 0)
            {
                return(RedirectToAction("SearchFlights"));
            }

            //Save SearchParameters and SearchResults
            _SearchFlightsLogic.SaveSearchParameters(searchFlightsViewModel.SearchParameters);
            _SearchFlightsLogic.LinkSearchParametersToSearchResults(listOfResults, _SearchFlightsLogic.GetSearchParametersByParameters(searchFlightsViewModel.SearchParameters).ID);
            _SearchFlightsLogic.SaveListOfSearchResults(listOfResults);

            //Add SearchResults to ViewModel as PagedList
            resultsViewModel.SearchResults = listOfResults.OrderBy(x => x.ID).ToPagedList(1, 3);

            return(View("Results", resultsViewModel));
        }
Ejemplo n.º 3
0
        public IEnumerable <Flight> SearchAvaibleFlights(SearchFlightsViewModel filters)
        {
            var jsonFilters = new FiltersJsonObject();

            IEnumerable <Flight> result =
                this._apiConn.SearchFlights(filters, jsonFilters).ToImmutableList();

            return(result);
        }
Ejemplo n.º 4
0
        public ActionResult SearchFlights()
        {
            SearchFlightsViewModel searchFlightsViewModel = new SearchFlightsViewModel()
            {
                Currency = _SearchFlightsLogic.Currencies
            };

            return(View(searchFlightsViewModel));
        }
Ejemplo n.º 5
0
        // This method creates the json string with the query data.
        // It receives the filters to search from the view-model and put the data into
        // FiltersJsonObject. This last object is serialized as a Json string.
        private string PrepareJson(SearchFlightsViewModel filters, FiltersJsonObject queryApiJson)
        {
            queryApiJson.Destination = filters.Destination;
            queryApiJson.Origin      = filters.Origin;
            queryApiJson.From        = filters.From.ToString("yyyy-MM-dd");

            string jsonFilters = JsonConvert.SerializeObject(queryApiJson);

            return(jsonFilters);
        }
Ejemplo n.º 6
0
        public ActionResult Search([FromForm] SearchFlightsViewModel m)
        {
            List <Airlines> airlinesAll = uow.Airlines.GetAll();
            List <Pilot>    pilotsAll   = uow.Pilot.GetAll();
            List <Flight>   flightsAll  = uow.Flight.GetAll();
            Flight          f1          = uow.Flight.FindById(m.startID);
            String          start       = f1.StartDestination;
            Flight          f2          = uow.Flight.FindById(m.endID);
            String          end         = f2.EndDestination;
            DateTime        onlyDate    = m.Date.Date;

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

            foreach (Flight flight in flightsAll)
            {
                if (flight.Date.Date == onlyDate && flight.StartDestination == start && flight.EndDestination == end)
                {
                    flightsSearched.Add(new Flight
                    {
                        StartDestination  = flight.StartDestination,
                        EndDestination    = flight.EndDestination,
                        Date              = flight.Date,
                        DurationInMinutes = flight.DurationInMinutes,
                        PilotID           = flight.PilotID,
                        Price             = flight.Price
                    }
                                        );
                }
            }
            if (flightsSearched.Count == 0)
            {
            }
            FlightsWithAirlineWithPilot model = new FlightsWithAirlineWithPilot
            {
                Flights  = flightsSearched,
                Airlines = airlinesAll,
                Pilots   = pilotsAll
            };

            return(View("SearchFlights", model));
        }
Ejemplo n.º 7
0
        public ActionResult Search()
        {
            List <Flight>         flightsAll        = uow.Flight.GetAll();
            List <SelectListItem> startDestinations = new List <SelectListItem>();
            List <SelectListItem> endDestinations   = new List <SelectListItem>();

            foreach (Flight flight in flightsAll)
            {
                if (!startDestinations.Any(item => item.Text == flight.StartDestination))
                {
                    startDestinations.Add(new SelectListItem
                    {
                        Text  = flight.StartDestination,
                        Value = flight.FlightID.ToString()
                    }
                                          );
                }
            }

            foreach (Flight flight in flightsAll)
            {
                if (!endDestinations.Any(item => item.Text == flight.EndDestination))
                {
                    endDestinations.Add(new SelectListItem
                    {
                        Text  = flight.EndDestination,
                        Value = flight.FlightID.ToString()
                    }
                                        );
                }
            }

            SearchFlightsViewModel model = new SearchFlightsViewModel
            {
                startDestinations = startDestinations,
                endDestinations   = endDestinations
            };

            return(View("Search", model));
        }
Ejemplo n.º 8
0
        // This is the principal method. It uses the two previous methods for search avaible flights in the api,
        // and if it finds return a list of flights, but if it doesn´t find any flight it throws a exception.
        public List <Flight> SearchFlights(SearchFlightsViewModel filters,
                                           FiltersJsonObject queryApiJson)
        {
            var           jsonFilters = PrepareJson(filters, queryApiJson);
            dynamic       result      = this._apiConn.Post(this.ApiUrl, jsonFilters);
            List <Flight> flights     = null;

            if (result != null)
            {
                flights = GetFlights(result);
                bool isEmptyList = flights[0] == null;

                if (!isEmptyList)
                {
                    return(flights);
                }
                else
                {
                    flights = null;
                }
            }

            return(flights);
        }