public IActionResult Index( int page = 1, string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int?itemsPerPage = null ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, DelegateFilterCookieName, DelegateActiveStatusFilterOptions.IsActive.FilterValue ); var centreId = User.GetCentreId(); var jobGroups = jobGroupsDataService.GetJobGroupsAlphabetical(); var customPrompts = promptsService.GetCentreRegistrationPrompts(centreId).ToList(); var delegateUsers = userDataService.GetDelegateUserCardsByCentreId(centreId); var promptsWithOptions = customPrompts.Where(customPrompt => customPrompt.Options.Count > 0); var availableFilters = AllDelegatesViewModelFilterOptions.GetAllDelegatesFilterViewModels( jobGroups, promptsWithOptions ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), new FilterOptions( existingFilterString, availableFilters, DelegateActiveStatusFilterOptions.IsActive.FilterValue ), new PaginationOptions(page, itemsPerPage) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( delegateUsers, searchSortPaginationOptions ); var model = new AllDelegatesViewModel( result, customPrompts, availableFilters ); Response.UpdateFilterCookie(DelegateFilterCookieName, result.FilterString); return(View(model)); }
public void GetAllDelegatesFilterViewModels_should_return_correct_job_group_filter() { // Given var(jobGroups, expectedFilter) = GetSampleJobGroupsAndFilter(); // When var result = AllDelegatesViewModelFilterOptions.GetAllDelegatesFilterViewModels(jobGroups, new List <CustomPrompt>()); // Then result.Should().ContainEquivalentOf(expectedFilter); }