// GET: Books by type public async Task <IActionResult> Types() { var model = new BookCategoriesViewModel(); var GroupedBooks = await( from c in _context.Category join b in _context.Book on c.CategoryId equals b.CategoryId group new { c, b } by new { c.CategoryId, c.CategoryName } into grouped select new GroupedBooks { TypeId = grouped.Key.CategoryId, TypeName = grouped.Key.CategoryName, BookCount = grouped.Select(x => x.b.BookId).Count(), Books = grouped.Select(x => x.b).Take(5).ToList() }).ToListAsync(); model.GroupedBooks = GroupedBooks; return(View(model)); }
// GET: BooksCategories/Details/5 public ActionResult Details(int?bookId, int?categoryId) { if (bookId == null && categoryId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BooksCategories booksCategories = db.BooksCategories.Find(bookId, categoryId); if (booksCategories == null) { return(HttpNotFound()); } BookCategoriesViewModel vm = new BookCategoriesViewModel() { Books = db.Books.SingleOrDefault(b => b.BookID == booksCategories.BookId), Categories = db.Categories.SingleOrDefault(c => c.CategoryID == booksCategories.CategoryId), CategoriesList = null }; return(View(vm)); }