Exemple #1
0
        public async Task <GerarCodigoResponse> GerarCodigo(GerarCodigoRequest request)
        {
            var response = new GerarCodigoResponse();

            var handler = new HttpClientHandler();

            //handler.ClientCertificates.Add(CertificadoRequisicao.Obter(this._dadosBhn.Certificado));

            using (var httpClient = new HttpClient(handler))
            {
                var gerarEGiftUrl = this._dadosBhn.RotaGerarEGift;

                httpClient.BaseAddress = new Uri(this._dadosBhn.HttpAddress);
                httpClient.DefaultRequestHeaders.Accept.Clear();

                var gerarEGiftRequest = new HttpRequestMessage(HttpMethod.Post, httpClient.BaseAddress + gerarEGiftUrl);


                using (var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"))
                {
                    gerarEGiftRequest.Content = content;
                    var gerarEGiftResponse = await httpClient.SendAsync(gerarEGiftRequest);

                    var responseString = await gerarEGiftResponse.Content.ReadAsStringAsync();

                    var responseObject = JsonConvert.DeserializeObject <GerarCodigoResponse>(responseString);

                    return(responseObject);
                }
            }
        }
        public async Task <GerarCodigoResponse> GerarCodigo(GerarCodigoRequest request)
        {
            _logger.Log("Iniciando Gerar Código Postagem", request);
            GerarCodigoResponse response = await _service.GerarCodigo(request);

            _logger.Log("Iniciando Gerar Código Postagem", request, response);
            return(response);
        }
Exemple #3
0
        public async Task <GerarCodigoResponse> GerarCodigo(GerarCodigoRequest request)
        {
            GerarCodigoResponse response = new GerarCodigoResponse();

            try
            {
                ValidationResult validationResult = request.Validate();
                if (!validationResult.IsValid)
                {
                    response.Valido = false;
                    foreach (ValidationFailure failure in validationResult.Errors)
                    {
                        response.AdicionarMensagemErro(TipoMensagem.Validacao, failure.ErrorMessage);
                    }
                }
                else
                {
                    string     correlationId = request.GetHeader(Const.CorrelationID);
                    PostagemId postagemId    = request.Map();
                    Postagem   postagem      = await _postagemFactory.Gerar(postagemId, correlationId);

                    await postagem.CancelarCodigoExistente(correlationId);

                    BusinessResult result = await postagem.CriarCodigo(correlationId);

                    if (!result.Valido)
                    {
                        response.Valido = result.Valido;
                        response.AdicionarMensagemErro(TipoMensagem.ErroNegocio, result.Mensagens.First().Conteudo);
                    }
                    else
                    {
                        await postagem.AtualizarCodigo(correlationId);

                        response.Postagem = postagem;
                    }
                }
            }
            catch (ApplicationException appEx)
            {
                response.Valido = false;
                response.AdicionarMensagemErro(TipoMensagem.ErroNegocio, appEx.Message);
            }
            catch (Exception ex)
            {
                response.Valido = false;
                response.AdicionarMensagemErro(TipoMensagem.ErroAplicacao, ex.StackTrace);
            }
            return(response);
        }
Exemple #4
0
        public async Task <GerarCodigoResponse> ValidateAsync(GerarCodigoRequest request)
        {
            var response = new GerarCodigoResponse();

            if (request == null)
            {
                return(GetRequestIsNullResponse <GerarCodigoResponse>());
            }

            var validation = request.Validate();

            if (!validation.IsValid)
            {
                var codeMessages = await _repository.ListarAsync(validation);

                response = GetInvalidRequestResponse <GerarCodigoResponse>(codeMessages);
            }

            return(response);
        }
Exemple #5
0
        public void Log(string message, GerarCodigoRequest request, GerarCodigoResponse response = null, Exception ex = null)
        {
            var keys          = new List <string>();
            var dataContainer = new List <ContainerItem>();

            if (request != null)
            {
                keys.Add(nameof(request.Companhia));
                dataContainer.Add(new ContainerItem(nameof(request.Companhia), request.Companhia.ToString()));

                keys.Add(nameof(request.IdUnidadeNegocio));
                dataContainer.Add(new ContainerItem(nameof(request.IdUnidadeNegocio), request.IdUnidadeNegocio.ToString()));

                keys.Add(nameof(request.IdSku));
                dataContainer.Add(new ContainerItem(nameof(request.IdSku), request.IdSku.ToString()));

                keys.Add(nameof(request.IdPedido));
                dataContainer.Add(new ContainerItem(nameof(request.IdPedido), request.IdPedido.ToString()));

                keys.Add(nameof(request.IdPedidoEntrega));
                dataContainer.Add(new ContainerItem(nameof(request.IdPedidoEntrega), request.IdPedidoEntrega.ToString()));

                keys.Add(nameof(request.Funcionario));
                dataContainer.Add(new ContainerItem(nameof(request.Funcionario), request.Funcionario));

                keys.Add(nameof(request.Protocolo));
                dataContainer.Add(new ContainerItem(nameof(request.Protocolo), request.Protocolo));
            }

            var content = new { request, response };

            if (ex != null)
            {
                _log.Error(request.CorrelationId, ex, message, request.CorrelationId, entity: LogInfo.GerarCodigoPostagem.MainEntity, keys: keys, process: LogInfo.GerarCodigoPostagem.Description, content: content, dataContainer: dataContainer);
            }
            else
            {
                _log.Info(request.CorrelationId, message, request.CorrelationId, entity: LogInfo.GerarCodigoPostagem.MainEntity, keys: keys, process: LogInfo.GerarCodigoPostagem.Description, content: content, dataContainer: dataContainer);
            }
        }