public LearningAimsSearchModel GetLearningAimsSearchModel(BasicSearchModel basicSearchModel) { var searchModel = new LearningAimsSearchModel(); if (!string.IsNullOrEmpty(basicSearchModel.SearchTerm)) { searchModel.SearchTerm = basicSearchModel.SearchTerm; } if (!string.IsNullOrEmpty(basicSearchModel.Level)) { searchModel.Levels.Add(basicSearchModel.Level); } if (!string.IsNullOrEmpty(basicSearchModel.AwardingBody)) { searchModel.AwardingBodies.Add(basicSearchModel.AwardingBody); } if (!string.IsNullOrEmpty(basicSearchModel.TeachingYear)) { searchModel.TeachingYears.Add(basicSearchModel.TeachingYear); } return(searchModel); }
public StandardSearchModel GetStandardSearchModel(BasicSearchModel basicSearchModel) { var searchModel = new StandardSearchModel(); if (!string.IsNullOrEmpty(basicSearchModel.SearchTerm)) { searchModel.SearchTerm = basicSearchModel.SearchTerm; } return(searchModel); }
public FrameworkSearchModel GetFrameworkSearchModel(BasicSearchModel basicSearchModel) { var searchModel = new FrameworkSearchModel(); if (!string.IsNullOrEmpty(basicSearchModel.SearchTerm)) { searchModel.SearchTerm = basicSearchModel.SearchTerm; } return(searchModel); }
private bool ShouldIncludeSearchResults(BasicSearchModel basicSearchModel) { // Filter state is only stored clientside and to avoid HTTP Posts (which neagtively affect the back button) // we will not display results initially where we know filters have been applied. The client code will know // to get the results once the page has been loaded. if (basicSearchModel?.HasFilters == true) { return(false); } return(true); }
public void GetSearchModel_Returns_Valid_Model() { var basicSearchModel = new BasicSearchModel { SearchTerm = "test term", Level = "test level" }; var factory = new SearchModelFactory(); var result = factory.GetLearningAimsSearchModel(basicSearchModel); result.SearchTerm.Should().Be(basicSearchModel.SearchTerm); result.Levels.Single().Should().Be(basicSearchModel.Level); }
private void ValidateSearch(BasicSearchModel searchModel, HomeViewModel viewModel) { var searchTermError = _clientValidationService.SearchTermLengthValid(searchModel.SearchTerm); if (!string.IsNullOrEmpty(searchTermError)) { viewModel.ValidationErrors.Add(searchTermError); } var filterError = _clientValidationService.FilterLengthValid(searchModel.AwardingBody); if (!string.IsNullOrEmpty(filterError)) { viewModel.ValidationErrors.Add(filterError); } }
private IActionResult RedirectToNewSearch(TSearchModel searchModel) { var basicSearchModel = new BasicSearchModel { SearchTerm = searchModel.SearchTerm, TeachingYear = searchModel.TeachingYears?.FirstOrDefault() }; var routeStrategy = _resultRouteStrategies.SingleOrDefault(r => r.SearchType == searchModel.SearchType); if (routeStrategy != null) { return(RedirectToAction(routeStrategy.Action, routeStrategy.Controller, basicSearchModel)); } return(RedirectToAction("Index", basicSearchModel)); }
public IActionResult Index([FromForm] BasicSearchModel searchModel, LearningType searchType) { var model = new HomeViewModel(); ValidateSearch(searchModel, model); if (model.ValidationErrors.Any()) { return(RedirectToAction("Index", model)); } var routeStrategy = _resultRouteStrategies.SingleOrDefault(r => r.SearchType == searchType); if (routeStrategy != null) { return(RedirectToAction(routeStrategy.Action, routeStrategy.Controller, searchModel)); } return(RedirectToAction("Index", searchModel)); }
public ActionResult BasicSearch(string query, int?currentPage = null, int?pageSize = null) { currentPage = currentPage ?? 0; pageSize = pageSize ?? 20; var searchResult = ProjectLogic.Search(query, currentPage.Value, pageSize.Value); var results = ModelConverter.ConvertToSearch(searchResult.Results); var model = new BasicSearchModel { CurrentPage = currentPage.Value, PageSize = pageSize.Value, Query = query, ModelName = "Project", HasMoreResults = searchResult.HasMore, HasPriorResults = searchResult.HasPrevious, Results = results }; return(View("BasicSearch", model)); }
protected override LearningAimsSearchModel GetSearchModel(BasicSearchModel basicSearchModel) { return(_searchModelFactory.GetLearningAimsSearchModel(basicSearchModel)); }
protected override FrameworkSearchModel GetSearchModel(BasicSearchModel basicSearchModel) { return(_searchModelFactory.GetFrameworkSearchModel(basicSearchModel)); }
protected async Task <SearchResultsViewModel <TSearchModel, TResults> > PopulateViewModel(BasicSearchModel basicSearchModel = null, TSearchModel searchModel = null, bool includeSearchResults = true) { if (searchModel == null) { searchModel = GetSearchModel(basicSearchModel); } searchModel.SearchType = _searchType; LookUpModel lookups; var results = new List <TResults>(); if (includeSearchResults) { var learningAimsTask = GetSearchResults(searchModel); var lookupsTask = _lookupApiService.GetLookups(); await Task.WhenAll(learningAimsTask, lookupsTask); results = learningAimsTask.Result.ToList(); lookups = lookupsTask.Result; } else { lookups = await _lookupApiService.GetLookups(); } return(new SearchResultsViewModel <TSearchModel, TResults> { SearchModel = searchModel, Results = results, LookUpModel = lookups, RequiresClientSideRefresh = !includeSearchResults }); }
public async Task <IActionResult> Index(BasicSearchModel basicSearchModel = null) { var model = await PopulateViewModel(basicSearchModel, null, ShouldIncludeSearchResults(basicSearchModel)); return(View(model)); }
protected abstract TSearchModel GetSearchModel(BasicSearchModel basicSearchModel);
protected override StandardSearchModel GetSearchModel(BasicSearchModel basicSearchModel) { return(_searchModelFactory.GetStandardSearchModel(basicSearchModel)); }