private List <KeyValuePair <string, string> > ValidateRequest(BusinessesGetQuery request) { var issues = _validator.Validate(request).Errors; foreach (var issue in issues) { _errors.Add(new KeyValuePair <string, string>(issue.PropertyName, issue.ErrorMessage)); } return(_errors); }
public async Task <ActionResult <IEnumerable <Business> > > GetBusiness() { var query = new BusinessesGetQuery(); var queryResponse = await Mediator.Send(query); if (queryResponse.ErrorInfo.HasException) { return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError)); } if (queryResponse.Result.Count == 0) { return(NotFound()); } return(Ok(queryResponse.Result)); }
public async Task <QueryResponse <List <Business> > > Handle(BusinessesGetQuery request, CancellationToken cancellationToken) { var response = new QueryResponse <List <Business> >() { Errors = ValidateRequest(request) }; if (!response.Errors.Any()) { try { response.Result = _dbContext.Business.Where(request.QueryPredicate).ToList(); } catch (Exception e) { _logger.LogCritical(e.ToString()); response.ErrorInfo.UserErrorMessage = "An unknown error has occurred."; response.ErrorInfo.HasException = true; } } return(response); }