Пример #1
0
        public HttpResponseMessage BuscaPorId(int id)
        {
            try
            {
                var livro = _livroService.BuscarLivro(id);

                if (livro.Id == 0)
                {
                    JsonResult.Status  = false;
                    JsonResult.Message = "404 Not Found";
                    return(Request.CreateResponse(HttpStatusCode.NotFound, JsonResult));
                }

                JsonResult.Status  = true;
                JsonResult.Object  = livro;
                JsonResult.Message = "Encontrado com sucesso";
                return(Request.CreateResponse(HttpStatusCode.OK, JsonResult));
            }
            catch (Exception ex)
            {
                JsonResult.Status  = false;
                JsonResult.Message = ex.Message;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, JsonResult));
            }
        }