Exemplo n.º 1
0
        public async Task <IActionResult> GetBookById(int BookId)
        {
            var msg = CreateResponse(HttpStatusCode.InternalServerError, ApiErrorProvider.GetErrorResponse(ApiErrorCodes.InternalServiceError));

            if (!ModelState.IsValid)
            {
                msg = CreateResponse(HttpStatusCode.BadRequest, ApiErrorProvider.GetErrorResponse(ModelState));
            }
            else
            {
                try
                {
                    if (BookId <= 0)
                    {
                        return(CreateResponse(HttpStatusCode.NotFound,
                                              ApiErrorProvider.GetErrorResponse(ApiErrorCodes.NotFound)));
                    }

                    BookDomain bookInfo = await _libraryManager.GetBookInfoByBookId(BookId).ConfigureAwait(false);

                    if (bookInfo == null)
                    {
                        return(CreateResponse(HttpStatusCode.NotFound,
                                              ApiErrorProvider.GetErrorResponse(ApiErrorCodes.BookIdRequestIsInvalid)));
                    }

                    msg = CreateResponse(HttpStatusCode.OK, bookInfo);
                }
                catch (Exception ex)
                {
                    msg = CreateResponse(HttpStatusCode.InternalServerError, ApiErrorProvider.GetErrorResponse(ApiErrorCodes.InternalServiceError));
                }
            }

            return(msg);
        }