// GET: Books/Details/5
        public async Task <IActionResult> Details(int?id, string data)
        {
            if (bookRepo.CheckForBookByTitle(data))
            {
                ViewBag.book = bookRepo.GetBookByTitle(data);
                id           = ViewBag.book.BookID;
                AppUser user = await userManager.GetUserAsync(HttpContext.User);

                if (ViewBag.book.Owner == user.UserName)
                {
                    ViewBag.userBooks = ViewBag.book;
                }
            }

            if (id == null)
            {
                return(NotFound());
            }

            var book = await _context.Books
                       .FirstOrDefaultAsync(m => m.BookID == id);

            if (book == null)
            {
                return(NotFound());
            }

            return(View(book));
        }
        public void TestCheckForBookByTitle()
        {
            //Arrange
            repo = new FakeBookRepo();
            SeedBookData();
            foreach (Book b in books)
            {
                repo.AddBook(b);
            }

            //Act
            bool hp = repo.CheckForBookByTitle("Harry Potter and the Sorceror's Stone");
            bool pj = repo.CheckForBookByTitle("The Heroes of Olympus");

            //Assert
            Assert.True(hp);
            Assert.False(pj);
        }
        public async Task <IActionResult> Create(int reviewID, string text, string bookTitle, int bookRating)
        {
            if (bookRating < 1 || bookRating > 5)
            {
                ModelState.AddModelError(nameof(LoginViewModel.UserName),
                                         "Invalid bookRating");
            }
            else if (text.Contains(":/") || text.Contains("\"") || text.Contains(".." + "\\") || (text == null) ||
                     text.Contains("{") || text.Contains("<") || text.Contains("}") || text.Contains(">"))
            {
                ModelState.AddModelError(nameof(LoginViewModel.UserName),
                                         "Invalid Text");
            }

            if (bookRepo.CheckForBookByTitle(bookTitle) == false)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                AppUser user = await userManager.GetUserAsync(HttpContext.User);

                Review review = new Review()
                {
                    Reviewer   = user.UserName,
                    ReviewID   = reviewID,
                    Text       = text,
                    BookTitle  = bookTitle,
                    BookRating = bookRating
                };

                Book book = bookRepo.GetBookByTitle(review.BookTitle);
                book.Reviews.Add(review);
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(NotFound());
        }