예제 #1
0
        public async Task <bool> Handle(ValidarConsultorCommand 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/auth/verifica-usuario/{message.Email}");
                }
                catch (Exception)
                {
                    await _bus.RaiseEvent(new DomainNotification(message.MessageType, "Consultor encontrado.", message));

                    return(await Task.FromResult(false));
                }
            }
            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));
        }
예제 #2
0
 public async Task ValidarConsultor(string email)
 {
     var validarConsultorCommand = new ValidarConsultorCommand(email);
     await _bus.SendCommand(validarConsultorCommand);
 }