コード例 #1
0
        public async Task <ActionResult> Results(TraineeshipSearchViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                ViewBag.SearchReturnUrl = (Request != null && Request.Url != null) ? Request.Url.PathAndQuery : null;

                var response = _traineeshipSearchMediator.Results(model);

                switch (response.Code)
                {
                case TraineeshipSearchMediatorCodes.Results.ValidationError:
                    ModelState.Clear();
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View(response.ViewModel);

                case TraineeshipSearchMediatorCodes.Results.HasError:
                    ModelState.Clear();
                    SetUserMessage(response.Message.Text, response.Message.Level);
                    return View(response.ViewModel);

                case TraineeshipSearchMediatorCodes.Results.Ok:
                    ModelState.Remove("Location");
                    ModelState.Remove("Latitude");
                    ModelState.Remove("Longitude");

                    return View(response.ViewModel);
                }

                throw new InvalidMediatorCodeException(response.Code);
            }));
        }
コード例 #2
0
        public async Task <ActionResult> Results(TraineeshipSearchViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                ViewBag.SearchReturnUrl = Request?.Url?.PathAndQuery;

                var response = _traineeshipSearchMediator.Results(model);

                switch (response.Code)
                {
                case TraineeshipSearchMediatorCodes.Results.ValidationError:
                    ModelState.Clear();
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View(response.ViewModel);

                case TraineeshipSearchMediatorCodes.Results.HasError:
                    ModelState.Clear();
                    SetUserMessage(response.Message.Text, response.Message.Level);
                    return View(response.ViewModel);

                case TraineeshipSearchMediatorCodes.Results.ExactMatchFound:
                    ViewBag.SearchReturnUrl = null;
                    return RedirectToRoute(CandidateRouteNames.TraineeshipDetails, response.Parameters);

                case TraineeshipSearchMediatorCodes.Results.Ok:
                    ModelState.Remove("Location");
                    ModelState.Remove("Latitude");
                    ModelState.Remove("Longitude");
                    return View(response.ViewModel);
                }

                throw new InvalidMediatorCodeException(response.Code);
            }));
        }
コード例 #3
0
        public void ExactMatchFoundUsingVacancyReference()
        {
            var searchViewModel = new TraineeshipSearchViewModel
            {
                ReferenceNumber = "VAC000123456"
            };

            TraineeshipVacancyProvider.Setup(sp => sp.FindVacancies(It.IsAny <TraineeshipSearchViewModel>()))
            .Returns(new TraineeshipSearchResponseViewModel
            {
                ExactMatchFound = true,
                VacancySearch   = searchViewModel,
                Vacancies       = new List <TraineeshipVacancySummaryViewModel>
                {
                    new TraineeshipVacancySummaryViewModel
                    {
                        Id = 123456
                    }
                }
            });

            var response = Mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.ExactMatchFound, false, true);
        }
コード例 #4
0
        public TraineeshipSearchResponseViewModel FindVacancies(TraineeshipSearchViewModel search)
        {
            _logger.Debug("Calling SearchProvider to find traineeship vacancies.");
            string vacancyReference;
            var    searchLocation     = _traineeshipSearchMapper.Map <TraineeshipSearchViewModel, Location>(search);
            var    isVacancyReference = VacancyHelper.TryGetVacancyReference(search.ReferenceNumber, out vacancyReference);

            try
            {
                var searchRequest = new TraineeshipSearchParameters
                {
                    Location     = searchLocation,
                    PageNumber   = search.PageNumber,
                    PageSize     = search.ResultsPerPage,
                    SearchRadius = search.WithinDistance,
                    SortType     = search.SortType
                };
                if (isVacancyReference)
                {
                    searchRequest.VacancyReference = vacancyReference;
                }

                var searchResults = _traineeshipSearchService.Search(searchRequest);

                if (searchResults.Total == 1)
                {
                    var exactMatchResponse = _traineeshipSearchMapper.Map <SearchResults <TraineeshipSearchResponse, TraineeshipSearchParameters>, TraineeshipSearchResponseViewModel>(searchResults);
                    exactMatchResponse.ExactMatchFound = true;
                    return(exactMatchResponse);
                }

                if (searchResults.Total > 1)
                {
                    _logger.Info($"{searchResults.Total} results found for Vacancy Reference Number {vacancyReference}");
                }
                var searchResponse =
                    _traineeshipSearchMapper.Map <SearchResults <TraineeshipSearchResponse, TraineeshipSearchParameters>, TraineeshipSearchResponseViewModel>(
                        searchResults);

                searchResponse.TotalHits     = searchResults.Total;
                searchResponse.PageSize      = search.ResultsPerPage;
                searchResponse.VacancySearch = search;

                return(searchResponse);
            }
            catch (CustomException ex)
            {
                // ReSharper disable once FormatStringProblem
                _logger.Error("Find traineeship vacancies failed. Check inner details for more info", ex);
                return(new TraineeshipSearchResponseViewModel(VacancySearchResultsPageMessages.VacancySearchFailed));
            }
            catch (Exception e)
            {
                _logger.Error("Find traineeship vacancies failed. Check inner details for more info", e);
                throw;
            }
        }
コード例 #5
0
        public MediatorResponse <TraineeshipSearchViewModel> SearchValidation(TraineeshipSearchViewModel model)
        {
            var clientResult = _searchRequestValidator.Validate(model);

            if (!clientResult.IsValid)
            {
                return(GetMediatorResponse(TraineeshipSearchMediatorCodes.SearchValidation.ValidationError, model, clientResult));
            }
            return(GetMediatorResponse(TraineeshipSearchMediatorCodes.SearchValidation.Ok, model));
        }
        public TraineeshipSearchViewModel Build()
        {
            var viewModel = new TraineeshipSearchViewModel
            {
                SortType  = _sortType,
                SortTypes = new SelectList(new string[0])
            };

            return(viewModel);
        }
コード例 #7
0
        public void SearchByReferenceNumberValidationPass()
        {
            var searchViewModel = new TraineeshipSearchViewModel
            {
                ReferenceNumber = "VAC1234",
                Location        = null
            };

            var response = Mediator.SearchValidation(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.SearchValidation.Ok, true);
        }
コード例 #8
0
        public void SearchByReferenceNumberValidationError()
        {
            var searchViewModel = new TraineeshipSearchViewModel
            {
                ReferenceNumber = string.Empty,
                Location        = string.Empty
            };

            var response = Mediator.SearchValidation(searchViewModel);

            response.AssertValidationResult(TraineeshipSearchMediatorCodes.SearchValidation.ValidationError, true);
        }
コード例 #9
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void NoSearchParameters()
        {
            var mediator        = GetMediator();
            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = string.Empty
            };

            var response = mediator.Results(searchViewModel);

            response.AssertValidationResult(TraineeshipSearchMediatorCodes.Results.ValidationError, true);
        }
コード例 #10
0
        public void SaveLocationSearchToCookie()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = "Entered loaction"
            };

            var response = mediator.Results(searchViewModel);

            _userData[UserDataItemNames.LastSearchedLocation].Should().Be(searchViewModel.Location + "|0|0");
        }
コード例 #11
0
        public MediatorResponse <TraineeshipSearchViewModel> Index()
        {
            var traineeshipSearchViewModel = new TraineeshipSearchViewModel
            {
                WithinDistance = 40,
                Distances      = GetDistances(),
                SortTypes      = GetSortTypes(),
                SortType       = VacancySearchSortType.Distance,
                ResultsPerPage = GetResultsPerPage()
            };

            return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Index.Ok, traineeshipSearchViewModel));
        }
コード例 #12
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void LocationValidationError()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = InvalidLocation
            };

            var response = mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.Ok, true);

            var viewModel = response.ViewModel;

            viewModel.VacancySearch.ShouldBeEquivalentTo(searchViewModel);
        }
コード例 #13
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void LocationOk_SuggestedLocations()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = "London"
            };

            var response = mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.Ok, true);

            var viewModel = response.ViewModel;

            viewModel.LocationSearches.Should().NotBeNull();
            viewModel.LocationSearches.Count().Should().BeGreaterThan(0);
        }
コード例 #14
0
        public async Task <ActionResult> Index(TraineeshipSearchViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                ViewBag.SearchReturnUrl = Request?.Url?.PathAndQuery;
                var response = _traineeshipSearchMediator.SearchValidation(model);

                switch (response.Code)
                {
                case TraineeshipSearchMediatorCodes.SearchValidation.ValidationError:
                    ModelState.Clear();
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View("Index", response.ViewModel);

                case TraineeshipSearchMediatorCodes.SearchValidation.Ok:
                    return RedirectToRoute(CandidateRouteNames.TraineeshipResults, model.RouteValues);
                }
                throw new InvalidMediatorCodeException(response.Code);
            }));
        }
コード例 #15
0
ファイル: SearchProvider.cs プロジェクト: Valtech-NAS/Beta
        public TraineeshipSearchResponseViewModel FindVacancies(TraineeshipSearchViewModel search)
        {
            _logger.Debug("Calling SearchProvider to find traineeship vacancies.");

            var searchLocation = _traineeshipSearchMapper.Map <TraineeshipSearchViewModel, Location>(search);

            try
            {
                var searchRequest = new TraineeshipSearchParameters
                {
                    Location     = searchLocation,
                    PageNumber   = search.PageNumber,
                    PageSize     = search.ResultsPerPage,
                    SearchRadius = search.WithinDistance,
                    SortType     = search.SortType,
                };

                var searchResults = _traineeshipSearchService.Search(searchRequest);

                var searchResponse =
                    _traineeshipSearchMapper.Map <SearchResults <TraineeshipSearchResponse, TraineeshipSearchParameters>, TraineeshipSearchResponseViewModel>(
                        searchResults);

                searchResponse.TotalHits     = searchResults.Total;
                searchResponse.PageSize      = search.ResultsPerPage;
                searchResponse.VacancySearch = search;

                return(searchResponse);
            }
            catch (CustomException ex)
            {
                // ReSharper disable once FormatStringProblem
                _logger.Error("Find traineeship vacancies failed. Check inner details for more info", ex);
                return(new TraineeshipSearchResponseViewModel(VacancySearchResultsPageMessages.VacancySearchFailed));
            }
            catch (Exception e)
            {
                _logger.Error("Find traineeship vacancies failed. Check inner details for more info", e);
                throw;
            }
        }
コード例 #16
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void LocationOk()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = "London"
            };

            var response = mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.Ok, true);

            var viewModel = response.ViewModel;

            viewModel.Vacancies.Should().NotBeNullOrEmpty();

            var vacancies = viewModel.Vacancies.ToList();

            vacancies.Count.Should().Be(1);
        }
コード例 #17
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void NoResults()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = "Middle of Nowhere"
            };

            var response = mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.Ok, true);

            var viewModel = response.ViewModel;

            viewModel.Vacancies.Should().NotBeNull();

            var vacancies = viewModel.Vacancies.ToList();

            vacancies.Count.Should().Be(0);
        }
コード例 #18
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void LocationOk_ResultsPerPage()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location       = "London",
                ResultsPerPage = int.Parse(ResultsPerPage)
            };

            var response = mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.Ok, true);

            var viewModel = response.ViewModel;

            viewModel.ResultsPerPageSelectList.Should().NotBeNull();
            viewModel.ResultsPerPageSelectList.Count().Should().BeGreaterThan(0);

            _userData.ContainsKey(UserDataItemNames.ResultsPerPage).Should().BeTrue();
            _userData[UserDataItemNames.ResultsPerPage].Should().Be(ResultsPerPage);
        }
コード例 #19
0
ファイル: ResultsTests.cs プロジェクト: Valtech-NAS/Beta
        public void LocationOk_SortTypes()
        {
            var mediator = GetMediator();

            var searchViewModel = new TraineeshipSearchViewModel
            {
                Location = "London"
            };

            var response = mediator.Results(searchViewModel);

            response.AssertCode(TraineeshipSearchMediatorCodes.Results.Ok, true);

            var viewModel = response.ViewModel;

            viewModel.SortTypes.Should().NotBeNull();

            var sortTypes = viewModel.SortTypes.ToList();

            sortTypes.Count.Should().Be(3);
            sortTypes.Should().Contain(sli => sli.Value == VacancySearchSortType.ClosingDate.ToString());
            sortTypes.Should().Contain(sli => sli.Value == VacancySearchSortType.Distance.ToString());
            sortTypes.Should().Contain(sli => sli.Value == VacancySearchSortType.RecentlyAdded.ToString());
        }
コード例 #20
0
        public MediatorResponse <TraineeshipSearchViewModel> Index(Guid?candidateId)
        {
            var lastSearchedLocation = UserDataProvider.Get(UserDataItemNames.LastSearchedLocation);

            if (string.IsNullOrWhiteSpace(lastSearchedLocation) && candidateId.HasValue)
            {
                var candidate = _candidateServiceProvider.GetCandidate(candidateId.Value);
                UserDataProvider.Push(UserDataItemNames.LastSearchedLocation, lastSearchedLocation = candidate.RegistrationDetails.Address.Postcode);
            }

            var traineeshipSearchViewModel = new TraineeshipSearchViewModel
            {
                WithinDistance = 40,
                Distances      = GetDistances(false),
                SortTypes      = GetSortTypes(),
                SortType       = VacancySearchSortType.Distance,
                ResultsPerPage = GetResultsPerPage(),
                Location       = SplitSearchLocation(lastSearchedLocation, 0),
                Latitude       = SplitSearchLocation(lastSearchedLocation, 1).GetValueOrNull <double>(),
                Longitude      = SplitSearchLocation(lastSearchedLocation, 2).GetValueOrNull <double>(),
            };

            return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Index.Ok, traineeshipSearchViewModel));
        }
 private static bool HaveLatAndLongPopulated(TraineeshipSearchViewModel instance, string location)
 {
     return(instance.Latitude.HasValue && instance.Longitude.HasValue);
 }
コード例 #22
0
        public MediatorResponse <TraineeshipSearchResponseViewModel> Results(TraineeshipSearchViewModel model)
        {
            UserDataProvider.Pop(CandidateDataItemNames.VacancyDistance);

            if (model.ResultsPerPage == 0)
            {
                model.ResultsPerPage = GetResultsPerPage();
            }

            UserDataProvider.Push(UserDataItemNames.ResultsPerPage, model.ResultsPerPage.ToString(CultureInfo.InvariantCulture));

            model.Distances = GetDistances(false);
            model.ResultsPerPageSelectList = GetResultsPerPageSelectList(model.ResultsPerPage);

            var clientResult = _searchRequestValidator.Validate(model);

            if (!clientResult.IsValid)
            {
                return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.ValidationError,
                                           new TraineeshipSearchResponseViewModel {
                    VacancySearch = model
                },
                                           clientResult));
            }

            if (!HasGeoPoint(model))
            {
                // User did not select a location from the dropdown list, provide suggested locations.
                if (model.Location != null)
                {
                    var suggestedLocations = _searchProvider.FindLocation(model.Location.Trim());

                    if (suggestedLocations.HasError())
                    {
                        return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.HasError, new TraineeshipSearchResponseViewModel {
                            VacancySearch = model
                        }, suggestedLocations.ViewModelMessage, UserMessageLevel.Warning));
                    }

                    if (suggestedLocations.Locations.Any())
                    {
                        var location = suggestedLocations.Locations.First();

                        model.Location  = location.Name;
                        model.Latitude  = location.Latitude;
                        model.Longitude = location.Longitude;

                        model.LocationSearches = suggestedLocations.Locations.Skip(1).Select(each =>
                        {
                            var vsvm = new TraineeshipSearchViewModel
                            {
                                Location       = each.Name,
                                Latitude       = each.Latitude,
                                Longitude      = each.Longitude,
                                PageNumber     = model.PageNumber,
                                SortType       = model.SortType,
                                WithinDistance = model.WithinDistance,
                                ResultsPerPage = model.ResultsPerPage
                            };

                            vsvm.Hash = vsvm.LatLonLocHash();

                            return(vsvm);
                        }).ToArray();
                    }
                }
            }

            var locationResult = _searchLocationValidator.Validate(model);

            if (!locationResult.IsValid)
            {
                return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.Ok, new TraineeshipSearchResponseViewModel {
                    VacancySearch = model
                }));
            }

            UserDataProvider.Push(UserDataItemNames.LastSearchedLocation, string.Join("|", model.Location, model.Latitude, model.Longitude));

            var traineeshipSearchResponseViewModel = _traineeshipVacancyProvider.FindVacancies(model);

            traineeshipSearchResponseViewModel.VacancySearch = model;
            if (traineeshipSearchResponseViewModel.ExactMatchFound)
            {
                var id = traineeshipSearchResponseViewModel.Vacancies.Single().Id;
                return(GetMediatorResponse <TraineeshipSearchResponseViewModel>(TraineeshipSearchMediatorCodes.Results.ExactMatchFound, parameters: new { id }));
            }

            if (traineeshipSearchResponseViewModel.VacancySearch != null)
            {
                traineeshipSearchResponseViewModel.VacancySearch.SortTypes = GetSortTypes(model.SortType);
            }

            if (traineeshipSearchResponseViewModel.HasError())
            {
                return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.HasError, new TraineeshipSearchResponseViewModel {
                    VacancySearch = model
                }, traineeshipSearchResponseViewModel.ViewModelMessage, UserMessageLevel.Warning));
            }

            return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.Ok, traineeshipSearchResponseViewModel));
        }
 public TraineeshipSearchResponseViewModelBuilder WithVacancySearch(TraineeshipSearchViewModel vacancySearchViewModel)
 {
     _vacancySearchViewModel = vacancySearchViewModel;
     return(this);
 }
 public TraineeshipSearchResponseViewModelBuilder()
 {
     _vacancySearchViewModel = new TraineeshipSearchViewModelBuilder().Build();
 }