Exemplo n.º 1
0
        public async Task <IActionResult> Get([FromRoute] int id)
        {
            try
            {
                if (id == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(id), "Id Livro inválido!");
                }

                var livro = await _livroService.GetLivrosByIdAsync(id);

                if (livro == null)
                {
                    return(BadRequest(new { message = "Livro não encontrado" }));
                }

                return(Ok(livro));
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = "Erro buscar livro", exception = e.Message }));
            }
        }