Exemplo n.º 1
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));
        }
Exemplo n.º 3
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));
        }