Пример #1
0
        public IActionResult Post([FromRoute] int id)
        {
            var book = _booksRepository.GetBookById(id);

            if (book == null)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            return(Ok());
        }
Пример #2
0
        public BookEditForm(string id)
        {
            InitializeComponent();
            var context = new LibraryContext();

            _booksRepository = new BooksRepository(context);

            _book = _booksRepository.GetBookById(id);

            FillDetails();
        }
Пример #3
0
        public void Book_GetBookById_IdDoesNotExist()
        {
            // Arrange
            var repo = new BooksRepository(context);

            int bookId = (context.Books.OrderByDescending(u => u.Id).FirstOrDefault()).Id;

            // Act
            var book = repo.GetBookById(bookId + 1);

            // Arrange
            Assert.Fail("Should have thrown NotFoundException");
        }
Пример #4
0
        public void Book_GetBookById_IdExists()
        {
            // Arrange
            var repo = new BooksRepository(context);

            int bookId = (context.Books.OrderByDescending(u => u.Id).FirstOrDefault()).Id;

            // Act
            var book = repo.GetBookById(bookId);

            // Arrange
            Assert.AreEqual(bookId, book.Id);
            Assert.AreEqual("The Lord of The Rings", book.Title);
            Assert.AreEqual("J.R.R. Tolkien", book.Author);
        }
Пример #5
0
        public ActionResult Details(int id)
        {
            if (id <= 0)
            {
                id = 1;
            }

            var bookModel     = _booksRepository.GetBookById(id);
            var bookViewModel = new BookViewModel
            {
                Isbn         = bookModel.Isbn, //
                Author       = bookModel.Author,
                CategoryName = bookModel.CategoryModel.Name,
                Title        = bookModel.Title,
                ContactEmail = bookModel.ContactEmail, //
                Price        = bookModel.Price,        //
                Description  = bookModel.Description
            };

            return(View(bookViewModel));
        }
Пример #6
0
 public IActionResult Details(int id)
 {
     return(View(_booksRepository.GetBookById(id)));
 }