Example #1
0
 public static MvcHtmlString NoResultsForModel(this HtmlHelper helper, FlightResultViewModel model, string url)
 {
     if (model.ErrorEncountered)
     {
         return new MvcHtmlString("<div class=\"no-results-found\">Oops, looks like we ran into a problem. Please try again later :(</div>");
     }
     if (!model.Flights.Any())
     {
         return new MvcHtmlString("<div class=\"no-results-found\">Sorry, we couldn't find any results for that search. Please try <a href=/Search>again...</a></div>");
     }
     return new MvcHtmlString("");
 }
        public ActionResult Index(SearchParamsViewModel searchModel)
        {
            _elasticSearchService.GetDestinations();
            var resultViewModel = new FlightResultViewModel();

            try
            {
#if DEBUG
                resultViewModel.Flights = new List<Flight>
                    {
                        new Flight
                            {
                                ArrivalDate = DateTime.Now,
                                DepartureAirport = new Airport {Code = "MAN", Name = "Manchester"},
                                DepartureDate = DateTime.Now,
                                DestinationAirport = new Airport {Code = "RVN", Name = "Somewhere"},
                                Id = "1",
                                Nights = 1,
                                SeatsRemaining = 2
                            }
                    };
#else
                ISearchResponse<Flight> searchResponse = _elasticSearchService.Search(new LateSeatsQuery
                    {
                        DepartureAirport = searchModel.SelectedDepartureAirport,
                        Days = searchModel.SelectedDays,
                        DestinationAirport = searchModel.SelectedDestinationAirport,
                        MaxNights = searchModel.SelectedMaxNights,
                        SeatsRemaining = searchModel.SelectedSeatsRemaining,
                        SortBy = searchModel.SelectedSortBy
                    });
                resultViewModel.Flights = searchResponse.Hits.Select(x => x.Source);
#endif
            }
            catch (Exception e)
            {
                resultViewModel.ErrorEncountered = true;
            }

            return View("Index", resultViewModel);
        }