Пример #1
0
        public async Task <IActionResult> Index(int page = 1)
        {
            var totalPosts = await _postService.GetTotalPostCountAsync();

            var totalPages = (int)Math.Ceiling((decimal)totalPosts / (decimal)EntriesPerPage);

            if (page < 1)
            {
                return(RedirectToAction(nameof(Index), new { page = 1 }));
            }
            if (page > totalPages)
            {
                return(RedirectToAction(nameof(Index), new { page = totalPages }));
            }

            var posts = await _postService.GetPostsAsync((page - 1) *EntriesPerPage, EntriesPerPage);

            return(View(new JournalIndexViewModel
            {
                Pagination = new Pagination {
                    CurrentPage = page, TotalPages = totalPages
                },
                Posts = posts
            }));
        }
Пример #2
0
        public async Task <IActionResult> Index()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var posts = await _postService.GetPostsAsync(0, 99, allowUnpublished : true);

            return(View(posts));
        }