public async Task <bool> Handle(ValidarRepresentanteCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(await Task.FromResult(false)); } try { var client = _httpAppService.CreateClient(_serviceManager.UrlVileve); var token = await _httpAppService.OnPost <Token, object>(client, message.RequestId, "v1/auth/login", new { usuario = _serviceManager.UserVileve, senha = _serviceManager.PasswordVileve }); if (token == null || string.IsNullOrWhiteSpace(token.AccessToken)) { await _bus.RaiseEvent(new DomainNotification(message.MessageType, "Usuário de integração não encontrado.", message)); return(await Task.FromResult(false)); } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); try { await _httpAppService.OnGet <object>(client, message.RequestId, $"v1/consultor/consultar/{message.Cpf}"); await _bus.RaiseEvent(new DomainNotification(message.MessageType, "Representante encontrado.", message)); return(await Task.FromResult(false)); } catch (Exception) { // ignored } } catch (Exception e) { _logger.Log(LogLevel.Error, e, JsonSerializer.Serialize(new { message.RequestId, e.Message })); await _bus.RaiseEvent(new DomainNotification(message.MessageType, "O sistema está momentaneamente indisponível, tente novamente mais tarde.", message)); return(await Task.FromResult(false)); } return(await Task.FromResult(true)); }
public async Task ValidarRepresentante(string cpf) { var validarRepresentanteCommand = new ValidarRepresentanteCommand(cpf); await _bus.SendCommand(validarRepresentanteCommand); }