public async Task <IActionResult> DisplayBookDetails(string id) { string decryptedId = dataProtector.Unprotect(id); int bookId = Convert.ToInt32(decryptedId); GetBookDto book = bookRepository.GetBookDetails(bookId); if (book == null) { ViewBag.Object = "Book"; return(View("Views/Home/ObjectNotFound.cshtml", bookId)); } Category category = categoryRepository.GetCategory(book.CategoryId); if (category == null) { ViewBag.Object = "Category"; return(View("Views/Home/ObjectNotFound.cshtml", bookId)); } BookUser bookUser = new BookUser { StartDate = DateTime.Today, EndDate = DateTime.Today, BookId = book.Id }; if (User.Identity.IsAuthenticated) { var user = await userManager.FindByEmailAsync(User.Identity.Name); bookUser.UserId = user.Id; } else { bookUser.UserId = ""; } DisplayBookDetailsViewModel viewModel = new DisplayBookDetailsViewModel { Book = book, Category = category, BookUser = bookUser }; var getOrderdBook = bookUserRepository.Find(bookUser.BookId, bookUser.UserId); if (getOrderdBook == null) { viewModel.IsReserved = false; } else { viewModel.IsReserved = true; } return(View("Views/Book/DisplayBookDetails.cshtml", viewModel)); }
public DisplayBookDetailsViewModel GetDisplayBookDetailsViewModel(BookUser bookUser) { GetBookDto book = bookRepository.GetBookDetails(bookUser.BookId); Category category = categoryRepository.GetCategory(book.CategoryId); DisplayBookDetailsViewModel viewModel = new DisplayBookDetailsViewModel { Book = book, Category = category, BookUser = bookUser }; return(viewModel); }