public IActionResult Index() { var books = bookRepositoryGUI.GetBooks(); if (books.Count() <= 0) { ViewBag.msg = "there was a problem while Getting the books from teh darabase or books does not exist yet."; } var bookAuthorsCategoriesRatingViewModel = new List <BookAuthorsCategoriesRatingViewModel>(); foreach (var item in books) { var categories = categoryRepositoryGUI.GetAllCategoriesOfABook(item.Id).ToList(); if (categories.Count() <= 0) { ModelState.AddModelError(string.Empty, "Some Kind of error while Getting authors"); } var authors = authorRepositoryGUI.GetAuthorsOfABook(item.Id).ToList(); if (authors.Count() <= 0) { ModelState.AddModelError(string.Empty, "Some kind of error while Getting Authors"); } var rating = bookRepositoryGUI.GetBookRating(item.Id); bookAuthorsCategoriesRatingViewModel.Add(new BookAuthorsCategoriesRatingViewModel() { Authors = authors, Book = item, Categories = categories, Rating = rating }); } return(View(bookAuthorsCategoriesRatingViewModel)); }
public IActionResult Index() { var books = _bookRepository.GetBooks(); if (books.Count() <= 0) { ViewBag.Message = "There was a problem retrieving books from the database or no book exists"; } var bookAuthorsCategoriesRatingViewModel = new List <BookAuthorsCategoriesRatingViewModel>(); foreach (var book in books) { var authors = _authorRepository.GetAuthorsOfABook(book.Id).ToList(); if (authors.Count() <= 0) { ModelState.AddModelError("", "Some kind of error getting authors"); } var categories = _categoryRepository.GetAllCategoriesOfABook(book.Id).ToList(); if (categories.Count() <= 0) { ModelState.AddModelError("", "Some kind of error getting categories"); } var rating = _bookRepository.GetBookRating(book.Id); bookAuthorsCategoriesRatingViewModel.Add(new BookAuthorsCategoriesRatingViewModel { Book = book, Authors = authors, Categories = categories, Rating = rating }); } ViewBag.SuccessMessage = TempData["SuccessMessage"]; return(View(bookAuthorsCategoriesRatingViewModel)); }
public IActionResult Index() { var books = _bookRepository.GetBooks(); if (books.Count() <= 0) { ViewBag.Message = "Ther was a problem retrieving books from " + "the database or no book exists"; } var bACRViewModel = new List <BACRViewModel>(); foreach (var book in books) { var authors = _authorRepository.GetAuthorsOfABook(book.Id).ToList(); if (authors.Count() <= 0) { ModelState.AddModelError("", "Error getting authors"); } var categories = _categoryRepository.GetAllCategoriesOfABook(book.Id).ToList(); if (categories.Count() <= 0) { ModelState.AddModelError("", "Error getting categories"); } var rating = _bookRepository.GetBookRating(book.Id); bACRViewModel.Add(new BACRViewModel { Authors = authors, Book = book, Categories = categories, Rating = rating }); } return(View(bACRViewModel)); }