public When_Provider_Controller_SearchProvider_Post_Is_Called_With_Provider_In_UkRlp() { _providerService = Substitute.For <IProviderService>(); _providerService .SearchAsync(Arg.Any <long>()) .ReturnsNull(); _providerService .SearchReferenceDataAsync(Arg.Any <long>()) .Returns(new ProviderSearchResultDto { Id = 1, UkPrn = 10000546, Name = "Test Provider" }); var providerController = new ProviderController(_providerService, new MatchingConfiguration()); var controllerWithClaims = new ClaimsBuilder <ProviderController>(providerController).Build(); var viewModel = new ProviderSearchParametersViewModel { UkPrn = 10000546 }; _result = controllerWithClaims.SearchProviderByUkPrnAsync(viewModel).GetAwaiter().GetResult(); }
public async Task <IActionResult> SearchProviderByUkPrnAsync(ProviderSearchParametersViewModel viewModel) { if (!ModelState.IsValid) { return(View("SearchProvider", GetProviderSearchViewModel(viewModel))); } if (!viewModel.UkPrn.HasValue) { ModelState.AddModelError(nameof(ProviderSearchParametersViewModel.UkPrn), "You must enter a UKPRN"); return(View("SearchProvider", GetProviderSearchViewModel(viewModel))); } var searchResult = await _providerService.SearchAsync(viewModel.UkPrn.Value); if (IsValidProviderSearch(searchResult)) { return(View("SearchProvider", await SearchProvidersWithFundingAsync(viewModel))); } searchResult = await _providerService.SearchReferenceDataAsync(viewModel.UkPrn.Value); return(View("SearchProvider", IsValidProviderSearch(searchResult) ? GetProviderSearchUkRlpViewModel(viewModel, searchResult) : GetProviderSearchViewModel(viewModel))); }
private ProviderSearchViewModel GetProviderSearchViewModel(ProviderSearchParametersViewModel searchParametersViewModel) { searchParametersViewModel.ShowAllProvider = true; return(new ProviderSearchViewModel(searchParametersViewModel) { IsAuthorisedUser = HttpContext.User.IsAuthorisedAdminUser(_configuration.AuthorisedAdminUserEmail) }); }
private async Task <ProviderSearchViewModel> SearchProvidersWithFundingAsync(ProviderSearchParametersViewModel viewModel) { var resultsViewModel = GetProviderSearchViewModel(viewModel); resultsViewModel.SearchResults = new ProviderSearchResultsViewModel { Results = await _providerService.SearchProvidersWithFundingAsync(viewModel) }; return(resultsViewModel); }
public When_Provider_Controller_SearchProvider_Post_Is_Called_With_Empty_UkPrn() { _providerService = Substitute.For <IProviderService>(); _providerService .SearchAsync(Arg.Any <long>()) .ReturnsNull(); var providerController = new ProviderController(_providerService, new MatchingConfiguration()); var controllerWithClaims = new ClaimsBuilder <ProviderController>(providerController).Build(); var viewModel = new ProviderSearchParametersViewModel(); _result = controllerWithClaims.SearchProviderByUkPrnAsync(viewModel).GetAwaiter().GetResult(); }
private ProviderSearchViewModel GetProviderSearchUkRlpViewModel(ProviderSearchParametersViewModel searchParametersViewModel, ProviderSearchResultDto dto) { var viewModel = new ProviderSearchViewModel(searchParametersViewModel) { SearchResults = { IsUkRlp = true }, IsAuthorisedUser = HttpContext.User.IsAuthorisedAdminUser(_configuration.AuthorisedAdminUserEmail) }; viewModel.SearchResults.Results.Add(new ProviderSearchResultItemViewModel { Id = dto.Id, Name = dto.Name, UkPrn = dto.UkPrn }); return(viewModel); }
public ProviderSearchViewModel(ProviderSearchParametersViewModel searchParameters) { SearchParameters = searchParameters; }
public async Task <IList <ProviderSearchResultItemViewModel> > SearchProvidersWithFundingAsync(ProviderSearchParametersViewModel searchParameters) { return(await _repository.GetManyAsync(p => searchParameters.UkPrn == null || p.UkPrn == searchParameters.UkPrn.Value) .OrderBy(p => p.Name) .ProjectTo <ProviderSearchResultItemViewModel>(_mapper.ConfigurationProvider) .ToListAsync()); }