public JsonResult GetByOrdinal(int id)
        {
            var book = _bookService.FindByOrdinal(id);

            if (book == null)
            {
                return(ErrorResponse("Not found"));
            }

            return(SingleResult(BookViewModelHelpers.ConvertToViewModel(book)));
        }
示例#2
0
        public JsonResult Search(string searchString)
        {
            var dbBooks = _bookService.Search(searchString).ToList();

            if (!dbBooks.Any())
            {
                return(ErrorResponse());
            }

            return(MultipleResults(BookViewModelHelpers.ConvertToViewModels(dbBooks)));
        }
示例#3
0
        public JsonResult GetForSeries(int seriesId)
        {
            var dbBooks = _bookService.Series(seriesId).ToList();

            if (!dbBooks.Any())
            {
                return(ErrorResponse());
            }

            return(MultipleResults(BookViewModelHelpers.ConvertToBaseViewModels(dbBooks)));
        }
示例#4
0
        public JsonResult GetBookCover(int bookId)
        {
            var dbBook = _bookService.FindById(bookId);

            if (dbBook == null)
            {
                return(ErrorResponse());
            }

            return(SingleResult(BookViewModelHelpers.ConverToBookCoverViewModel(dbBook)));
        }
示例#5
0
        public JsonResult GetByName(string bookName)
        {
            if (string.IsNullOrWhiteSpace(bookName))
            {
                return(ErrorResponse("Book name is required"));
            }
            var book = _bookService.GetByName(bookName);

            if (book == null)
            {
                return(ErrorResponse("No book with that name could be found"));
            }

            return(SingleResult(BookViewModelHelpers.ConvertToViewModel(book)));
        }
        public JsonResult Search(string searchString)
        {
            if (string.IsNullOrWhiteSpace(searchString))
            {
                return(ErrorResponse("Search string cannot be empty"));
            }

            var books = _bookService.Search(searchString);

            if (!books.Any())
            {
                return(ErrorResponse("Cannot find any books with the provided search string"));
            }

            return(MultipleResults(BookViewModelHelpers.ConvertToViewModels(books.ToList())));
        }
示例#7
0
        public void BookService_GetBookByOrdinal_ReturnsOneBook()
        {
            // What is this test even testing?

            // Arrange
            var idForTest     = 1;
            var dbBook        = GetTestBookById(idForTest);
            var testViewModel = GetBookViewModels()
                                .FirstOrDefault(b => b.BookOrdinal == idForTest);
            // Act
            var viewModel = BookViewModelHelpers.ConvertToViewModel(dbBook);

            // Assert
            Assert.Equal(testViewModel.BookName, viewModel.BookName);
            Assert.Equal(testViewModel.BookDescription, viewModel.BookDescription);
            Assert.Equal(testViewModel.BookIsbn10, viewModel.BookIsbn10);
            Assert.Equal(testViewModel.BookIsbn13, viewModel.BookIsbn13);
        }