public async Task <ActionResult> Post([FromBody] LancamentoViewModel model)
        {
            try
            {
                var validator = new LancamentoValidator();
                var result    = await validator.ValidateAsync(model);

                if (!result.IsValid)
                {
                    return(BadRequest(new ApiBadRequestResponse(result.Errors)));
                }

                var lancamento = await _lancamentoAppService.Add(model.ToEntity());

                return(Created("Lancamento efetuado com sucesso.", new ApiCreatedResponse(lancamento)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> LancarAsync([FromServices] ILancamentoRepository repository, [FromServices] IContaRepository contaRepository, [FromBody] Lancamento request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var lancamento = new Lancamento
            {
                ContaCredito = new Conta
                {
                    ContaCodigo = request.ContaCredito.ContaCodigo,
                    ContaId     = await contaRepository.ObtemContaId(request.ContaCredito.ContaCodigo),
                },
                ContaDebito = new Conta
                {
                    ContaCodigo = request.ContaDebito.ContaCodigo,
                    ContaId     = await contaRepository.ObtemContaId(request.ContaDebito.ContaCodigo),
                },
                LancamentoValor = request.LancamentoValor
            };

            var validator        = new LancamentoValidator(repository);
            var validationResult = await validator.ValidateAsync(lancamento);

            if (!validationResult.IsValid)
            {
                foreach (var error in validationResult.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }

                return(BadRequest(ModelState));
            }

            await repository.SalvarLancamento(lancamento);

            return(Accepted());
        }