public Task <Notas02Notification> Handle(EditarClienteCommand request, CancellationToken cancellationToken) { var entity = new Models.Cliente(Guid.Empty, request.Nome); var validator = new RegistrarClienteValidator(); ValidateCliente(ref entity, validator); var result = validator.Validate(new Models.Cliente(Guid.Empty, request.Nome)); if (result.IsValid) { _writeRepository.Add(new Models.Cliente(Guid.Empty, request.Nome)); return(Task.FromResult((Notas02Notification) new Notas02SuccessNotification())); } var results = new Dictionary <string, string>(); foreach (var err in result.Errors) { results.Add(err.PropertyName, err.ErrorMessage); } return(Task.FromResult((Notas02Notification) new Notas02ErrorNotification(results))); }
private void ValidateCliente(ref Models.Cliente cliente, ClienteValidator validator) { cliente.ValidationResult = validator.Validate(cliente); }