// Retrieves all the authors and returns them to the view
        public IActionResult Index()
        {
            var model = new AuthorIndexModel();
            model.Authors = _authorService.GetAll();

            return View(model);
        }
예제 #2
0
        public static AuthorIndexModel GetAuthorIndexModel(int booksOnPage, int currentPage)
        {
            AuthorIndexModel model = new AuthorIndexModel();

            model.bookOnPageCount = booksOnPage;
            model.currentPage     = currentPage;
            int allBooksCount = manager.authorService.GetAuthorsCount();
            int maxPage       = allBooksCount % booksOnPage == 0 ? allBooksCount / booksOnPage : allBooksCount / booksOnPage + 1;

            maxPage               = maxPage == 0 ? 1 : maxPage;
            currentPage           = currentPage < maxPage ? currentPage < 1 ? 1 : currentPage : maxPage;
            model.bookOnPageCount = booksOnPage;
            model.currentPage     = currentPage;
            model.pageCount       = maxPage;
            model.Authors         =
                manager.authorService.OrderTake((currentPage - 1) * booksOnPage, booksOnPage)
                .Select(e => e.ToAuthorShortModel());
            return(model);
        }