Пример #1
0
 public Transacao(TransacaoRequest transacaoRequest)
 {
     DataTransacao  = DateTime.Now;
     ValorTransacao = transacaoRequest.ValorTransacao;
     ValorRepasse   = CalcularValorRepasse(transacaoRequest.ValorTransacao, transacaoRequest.NumeroParcelas);
     NumeroParcelas = transacaoRequest.NumeroParcelas;
     DigitosCartao  = transacaoRequest.NumeroCartao.Substring(12, 4);
     ClientId       = transacaoRequest.ClienteId;
 }
Пример #2
0
        public async Task retornar_status_code_500_quando_saldo_insuficiente_ao_efetuar_retirada()
        {
            var request = new TransacaoRequest {
                IdConta = 2, Valor = 1000
            };

            var httpResponseMessage = await _client.PostAsync("/conta/retirada", SerializeRequest(request));

            httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
        }
Пример #3
0
        public async Task Deve_efetuar_pagamento_na_conta_corrente()
        {
            var request = new TransacaoRequest {
                IdConta = 3, Valor = 100
            };

            var httpResponseMessage = await _client.PostAsync("/conta/pagamento", SerializeRequest(request));

            httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.Accepted);
        }
Пример #4
0
        public async Task retornar_status_code_500_quando_conta_corrente_nao_existente_ao_efetuar_deposito()
        {
            var request = new TransacaoRequest {
                IdConta = 5, Valor = 100
            };

            var httpResponseMessage = await _client.PostAsync("/conta/deposito", SerializeRequest(request));

            httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
        }
 public StatusCodeResult EfetuarTransacao(TransacaoRequest transacaoRequest)
 {
     try {
         transacao.EfetuarTransacao(transacaoRequest);
         return(StatusCode(StatusCodes.Status200OK));
     }
     catch (Exception) {
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Пример #6
0
        public IActionResult PostEfetuarRetiradaConta
        (
            [FromBody] TransacaoRequest request
        )
        {
            _efetuarDebitoUseCase.Execute(new TransacaoDto
            {
                Tipo      = TipoTransacao.Retirada,
                Valor     = request.Valor,
                IdConta   = request.IdConta,
                Descricao = request.Descricao
            });

            return(Accepted());
        }
Пример #7
0
        public IActionResult PostTransacao([FromBody] TransacaoRequest transacaoRequest)
        {
            try
            {
                var transacao = new Transacao(transacaoRequest);
                _context.Transacoes.Add(transacao);
                _context.SaveChanges();

                return(Created("Transacao", transacao));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Пример #8
0
        public void EfetuarTransacao(TransacaoRequest transacaoRequest)
        {
            Conta contaCredito = contaRepository.Get(transacaoRequest.ContaCreditoId);
            Conta contaDebito  = contaRepository.Get(transacaoRequest.ContaDebitoId);

            using (var transacao = unitOfWork.BeginTransaction())
            {
                contaCredito.Saldo += transacaoRequest.Valor;
                operacaoCredito.Adicionar(contaCredito, transacaoRequest.Valor);
                contaRepository.Update(contaCredito);

                contaDebito.Saldo -= transacaoRequest.Valor;
                operacaoDebito.Adicionar(contaDebito, transacaoRequest.Valor);
                contaRepository.Update(contaDebito);

                unitOfWork.Commit();
                transacao.Commit();
            }
        }
Пример #9
0
        private StringContent SerializeRequest(TransacaoRequest request)
        {
            var content = JsonConvert.SerializeObject(request);

            return(new StringContent(content, Encoding.UTF8, "application/json"));
        }