public async Task <CommandResponse <Business> > Handle(BusinessSaveCommand request, CancellationToken cancellationToken) { var result = new CommandResponse <Business>() { Errors = GetRequestErrors(request) }; if (result.Errors.Count == 0) { try { var aggregate = new AssociateAggregate(_dbContext); await aggregate.BusinessSaveAsync(request.Item); result.Result = (Business)request.Item; } catch (Exception e) { Console.WriteLine(e); result.ErrorInfo = new ErrorInfo() { UserErrorMessage = "An internal error has occured", HasException = true }; } } return(result); }
private List <KeyValuePair <string, string> > GetRequestErrors(BusinessSaveCommand request) { var issues = _validator.Validate((Business)request.Item).Errors; foreach (var issue in issues) { _errors.Add(new KeyValuePair <string, string>(issue.PropertyName, issue.ErrorMessage)); } return(_errors); }