コード例 #1
0
        public async Task <object> ObterProduto()
        {
            var obterProdutoCommand  = new ObterProdutoCommand();
            var obterProdutoResponse = await _bus.SendCommand(obterProdutoCommand);

            return(_notifications.HasNotifications() ? obterProdutoResponse : _mapper.Map <ProdutoViewModel>((SeguroProduto)obterProdutoResponse));
        }
コード例 #2
0
        public async Task <object> Handle(ObterProdutoCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(await Task.FromResult(false));
            }

            try
            {
                var client = _httpAppService.CreateClient(_serviceManager.UrlVileve);

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _user.Token);

                return(await Task.FromResult(await _httpAppService.OnGet <SeguroProduto>(client, message.RequestId, "v1/proposta/seguro/produtos")));
            }
            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));
            }
        }