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));
        }
示例#2
0
        public IActionResult Index()
        {
            var books = _bookRepository.GetBooks();

            if (books.Count() <= 0)
            {
                ViewBag.Message = "There was a problem retrieving books from database or no book exists";
            }

            var bookAuthorsCategoriesRatingViewModel = new List <BookAuthorsCategoriesRatingViewModel>();

            foreach (var book in books)
            {
                var authors = _authorRepository.GetAuthorOfABook(book.Id);
                if (authors.Count() <= 0)
                {
                    ModelState.AddModelError("", "some kind of error getting authors");
                }

                var categories = _categoryRepository.GetAllCategoriesOfABook(book.Id);
                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));
        }
示例#3
0
        public IActionResult Index()
        {
            var books = bookRepository.GetBooks();

            IEnumerable <AuthorDto>   authors    = new List <AuthorDto>();
            IEnumerable <CategoryDto> categories = new List <CategoryDto>();
            decimal rating = 0.0m;

            if (books.Count() <= 0)
            {
                ViewBag.Message = "There are problems retrieving books " +
                                  " or books does not exist in the database.";
            }

            IList <BookAuthorsCategoriesViewModel> allBooks = new List <BookAuthorsCategoriesViewModel>();

            foreach (var book in books)
            {
                authors = authorRepository.GetAllAuthorsFromBook(book.Id);
                if (authors.Count() <= 0)
                {
                    ModelState.AddModelError("", "There are problems retrieving authors of a book");
                }
                categories = categoryRepository.GetCategoriesFromBook(book.Id);
                if (categories.Count() <= 0)
                {
                    ModelState.AddModelError("", "There are problems retrieving categories of a book");
                }
                rating = bookRepository.BookRating(book.Id);

                allBooks.Add(new BookAuthorsCategoriesViewModel {
                    Book       = book,
                    Authors    = authors,
                    Categories = categories,
                    Rating     = rating
                });
            }
            return(View(allBooks));
        }
        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));
        }