Beispiel #1
0
        public ActionResult GetBooksByPageination(int draw, int start, int length)
        {
            var collection = HttpContext.Request.Form;
            var searchKey  = collection["search[value]"].ToString();

            BookOutputDto bookOutputDto;

            if (!String.IsNullOrEmpty(searchKey) && searchKey.Length > 2)
            {
                bookOutputDto = Services.BookServiceClient.GetBooksSearchRangeBy(start, length, searchKey, CurrentUserModel.UserId);
            }
            else
            {
                bookOutputDto = Services.BookServiceClient.GetBooksRangeBy(start, length, CurrentUserModel.UserId);
            }

            var returnformat = new BookReturnModel
            {
                Draw            = draw,
                RecordsTotal    = bookOutputDto.TotalBook,
                RecordsFiltered = bookOutputDto.TotalBook,
                Data            = bookOutputDto.Books as BookDto[]
            };



            return(Json(returnformat));
        }
Beispiel #2
0
        public BookReturnModel GetBookByID(int bookID)
        {
            try
            {
                BookService bookService = new BookService();

                Book dbBook = bookService.GetBookByID(bookID);
                if (dbBook == null)
                {
                    throw new Exception($"Could not find a book with the given ID: {bookID}"); // it is better if you throw your custom Exception!
                }
                BookReturnModel result = new BookReturnModel(dbBook);
                return(result);
            }
            catch (Exception ex)
            {
                BookReturnModel result = new BookReturnModel();
                result.ErrorMessage = ex.GetBaseException().Message;
                return(result);
            }
        }