Example #1
0
        private async Task <SearchResultsViewModel> GetSearchResults(string route, string postcode, int distance)
        {
            var viewModel = new SearchResultsViewModel();

            viewModel.Route    = route;
            viewModel.Distance = distance;
            viewModel.Postcode = postcode;

            var routeId = route.Replace("-", " ");

            var routes     = _repository.GetRoutes();
            var searchTask = _vacanciesService.GetByRoute(routeId, postcode, Convert.ToInt32(distance));

            await Task.WhenAll(routes, searchTask);

            var searchResults = searchTask.Result;

            if (searchResults != null)
            {
                viewModel.TotalResults = searchResults.Results.Count;
                viewModel.Results      = searchResults.Results.Where(w => w.DistanceInMiles <= distance).Take(100).ToList();

                viewModel.Location     = searchResults.searchLocation;
                viewModel.StaticMapUrl = _mappingService.GetStaticMapsUrl(searchResults.Results.Select(p => p.Location), "680", "530");

                viewModel.Country = searchResults.Country;
                viewModel.Routes  = routes.Result;
            }


            return(viewModel);
        }
Example #2
0
        public async Task <VacancySearchResult> GetByPostcode(string postcode, int distance)
        {
            var coordinates = await _geocodeService.GetFromPostCode(postcode);

            if (coordinates.ResponseCode == "OK")
            {
                var searchResults = new VacancySearchResult
                {
                    searchLocation = new Location()
                    {
                        Latitude = coordinates.Coordinates.Lat, Longitude = coordinates.Coordinates.Lon
                    }
                };

                var pageNumber     = 1;
                var vacancyApiList = GetVacancyList(distance, coordinates, pageNumber);

                while (vacancyApiList.Count == _apiMaxPageSize && vacancyApiList.Max(s => s.DistanceInMiles < distance))
                {
                    pageNumber++;

                    var list = GetVacancyList(distance, coordinates, pageNumber);
                    vacancyApiList.AddRange(list);

                    if (list.Count < _apiMaxPageSize)
                    {
                        break;
                    }
                }

                searchResults.Results = vacancyApiList.Where(w => w.TrainingType == TrainingType.Standard)
                                        .Select(_vacanciesMapper.Map)
                                        .ToList();

                Parallel.ForEach(searchResults.Results,
                                 vacancy => { vacancy.StaticMapUrl = _mappingService.GetStaticMapsUrl(vacancy.Location); });

                return(searchResults);
            }

            return(null);
        }
Example #3
0
        private async Task <SearchResultsViewModel> GetSearchResults(string route, string postcode, int distance)
        {
            var viewModel = new SearchResultsViewModel
            {
                Route = route, Distance = distance, Postcode = postcode
            };

            var searchTask = _mediator.Send(new GetVacanciesQuery
            {
                Distance = distance,
                Postcode = postcode,
                Route    = route.Replace("-", " ")
            });
            var staticContent = _mediator.GetModelForStaticContent();

            await Task.WhenAll(searchTask, staticContent);

            var searchResults = searchTask.Result;

            if (searchResults != null)
            {
                viewModel = searchResults;

                Parallel.ForEach(viewModel.Results.Where(c => c.Location != null),
                                 vacancy =>
                {
                    vacancy.StaticMapUrl =
                        _mappingService.GetStaticMapsUrl(vacancy.Location.Latitude, vacancy.Location.Longitude);
                });

                viewModel.Menu         = staticContent.Result.Menu;
                viewModel.BannerModels = staticContent.Result.BannerModels;
            }

            return(viewModel);
        }