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));
        }
Example #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));
        }
        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));
        }
Example #4
0
        public IActionResult GetAuthorById(int authorId)
        {
            var author = _authorRepository.GetAuthorById(authorId);

            if (author == null)
            {
                ModelState.AddModelError("", "Some kind of error getting author");
                ViewBag.Message = $"There was a problem retrieving author with id {authorId} " +
                                  $"From the database or no author with that id exists";
                author = new AuthorDto();
            }

            var country = _countryRepository.GetCountryOfAnAuthor(authorId);

            if (country == null)
            {
                ModelState.AddModelError("", "Some kind of error getting country");
                ViewBag.Message += $"There was a problem retrieving country with id {authorId} " +
                                   $"From the database or no country with that id exists";
                country = new CountryDto();
            }

            var bookCategories = new Dictionary <BookDto, IEnumerable <CategoryDto> >();
            var books          = _authorRepository.GetBooksByAuthor(authorId);

            if (books.Count() <= 0)
            {
                ViewBag.BookMessage = $"No books for {author.FirstName} {author.LastName} exists";
            }

            foreach (var book in books)
            {
                var categories = _categoryRepository.GetAllCategoriesOfABook(book.Id);
                bookCategories.Add(book, categories);
            }

            var authorCountryBooksCategoriesViewModel = new AuthorCountryBooksCategoriesViewModel
            {
                Author         = author,
                Country        = country,
                BookCategories = bookCategories
            };

            ViewBag.SuccessMessage = TempData["SuccessMessage"];
            return(View(authorCountryBooksCategoriesViewModel));
        }
        public IActionResult GetAuthorById(int authorId)
        {
            var author = _authorRespository.GetAuthorById(authorId);

            if (author == null)
            {
                ModelState.AddModelError("", $"There is no author with id:{authorId}");
                ViewBag.Message = $"There was a problem retrieving author with id {authorId} " +
                                  $"from the database or no author with this id exists";
                author = new AuthorDto();
            }

            var country = _countryRepository.GetCountryOfAnAuthor(authorId);

            if (country == null)
            {
                ModelState.AddModelError("", "Error getting a country");
                ViewBag.Message += $"There was a problem retrieving country of an author with Id={authorId} " +
                                   $"from the database or no country exists for this author";
                country = new CountryDto();
            }

            var books = _authorRespository.GetBooksByAuthor(authorId);
            IDictionary <BookDto, IEnumerable <CategoryDto> > bookCategories = new Dictionary <BookDto, IEnumerable <CategoryDto> >();

            if (books.Count() <= 0)
            {
                ViewBag.BookMessage = $"No books for {author.FirstName} {author.LastName} exists.";
            }
            foreach (var book in books)
            {
                var categories = _categoryRepository.GetAllCategoriesOfABook(book.Id);
                bookCategories.Add(book, categories);
            }

            var ACBCVM = new AuthorCountryBookCategoriesViewModel
            {
                Author         = author,
                Country        = country,
                BookCategories = bookCategories
            };

            return(View(ACBCVM));
        }
Example #6
0
        public IActionResult GetAuthorById(int authorid)
        {
            var author = _authorRepositoryGUI.GetAuthorByID(authorid);

            if (author == null)
            {
                ModelState.AddModelError(string.Empty, "Some kind of error while Getting the Author");

                ViewBag.reviewMsg += $"There was an error while getting the Author from the database or Review of {authorid} does not exist";

                author = new AuthorDto();
            }

            var country = _countryRepositoryGUI.GetCountryOfAuthor(authorid);

            if (country == null)
            {
                ModelState.AddModelError(string.Empty, "Some kind of error while Getting the country");

                ViewBag.reviewMsg += $"There was an error while getting the country from the database or Review of {authorid} does not exist";

                country = new CountryDto();
            }
            var bookCategories = new Dictionary <BookDto, IEnumerable <CategoryDto> >();

            var books = _authorRepositoryGUI.GetBooksByAuthor(authorid);

            foreach (var item in books)
            {
                var categories = _categoryRepositoryGUI.GetAllCategoriesOfABook(item.Id);
                bookCategories.Add(item, categories);
            }

            var mainModel = new AuthoCountryBooksCategoriesViewModel
            {
                author         = author,
                BookCategories = bookCategories,
                country        = country
            };

            return
                (View(mainModel));
        }