示例#1
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 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();
            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.
                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
                }));
            }

            var traineeshipSearchResponseViewModel = _searchProvider.FindVacancies(model);

            traineeshipSearchResponseViewModel.VacancySearch.SortTypes = GetSortTypes(model.SortType);

            return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.Ok, traineeshipSearchResponseViewModel));
        }