public async Task <List <Standard> > Handle(SearchStandardsRequest request, CancellationToken cancellationToken) { _logger.LogInformation("Handling Search Standards Request"); var searchstring = _cleanser.UnescapeAndRemoveNonAlphanumericCharacters(request.SearchTerm); var validationResponse = _validator.ValidatorSearchStandardsRequest(new SearchStandardsValidationRequest { Searchstring = searchstring }); if (!validationResponse.IsValid) { var message = validationResponse.Errors.Aggregate(string.Empty, (current, error) => current + error.ErrorMessage + "; "); _logger.LogError(message); if (validationResponse.Errors.Any(x => x.StatusCode == ValidationStatusCode.BadRequest.ToString())) { throw new BadRequestException(message); } throw new Exception(message); } var isAnInt = int.TryParse(searchstring, out var intSearchString); var allStandards = await _standardService.GetLatestStandardVersions(); return(isAnInt ? allStandards.Where(x => x.LarsCode == intSearchString).ToList() : allStandards.Where(x => _cleanser.UnescapeAndRemoveNonAlphanumericCharacters(x.Title.ToLower()).Contains(searchstring.ToLower())).ToList()); }
public async Task <ValidationResponse> Handle(SearchStandardsValidationRequest request, CancellationToken cancellationToken) { var searchstring = _cleanser.UnescapeAndRemoveNonAlphanumericCharacters(request.Searchstring); var result = _validator.ValidatorSearchStandardsRequest(new SearchStandardsValidationRequest { Searchstring = searchstring }); return(await Task.FromResult(result)); }