Beispiel #1
0
        public async Task <IActionResult> InserirCreditoAsync([FromRoute] string token, [FromBody] IEnumerable <Extrato> extratos)
        {
            try
            {
                await _service.ValidateTokenAsync(token);

                var result = _domain.Inserir(extratos);

                var mainExtrato = extratos.FirstOrDefault();

                await _emailHandler.EnviaEmailAsync(token, mainExtrato);

                return(Ok(result));
            }
            catch (ServiceException e)
            {
                return(StatusCode(401, e.Message));
            }
            catch (InvalidTokenException e)
            {
                return(StatusCode(401, e.Message));
            }
            catch (ExtratoException e)
            {
                return(StatusCode(400, e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, "Ocorreu um erro interno no servidor."));
            }
        }