public async Task <IActionResult> Index(int page = 1) { var pagesize = _blogConfig.ContentSettings.PostListPageSize; var posts = await _postService.GetPagedPostsAsync(pagesize, page); var count = _cache.GetOrCreate(CacheDivision.General, "postcount", _ => _postService.CountVisiblePosts()); var list = new StaticPagedList <PostListEntry>(posts, page, pagesize, count); return(View(list)); }
public async Task <IActionResult> Index(int page = 1, [FromServices] IMemoryCache memoryCache = null) { try { var pagesize = _blogConfig.ContentSettings.PostListPageSize; var postList = await _postService.GetPagedPostsAsync(pagesize, page); var postCount = memoryCache.GetOrCreate(StaticCacheKeys.PostCount, entry => _postService.CountVisiblePosts().Item); var postsAsIPagedList = new StaticPagedList <PostListItem>(postList, page, pagesize, postCount); return(View(postsAsIPagedList)); } catch (Exception e) { Logger.LogError(e, "Error getting post list."); return(ServerError("Error getting post list.")); } }
public async Task <IActionResult> Index(int page = 1) { try { var pagesize = _blogConfig.ContentSettings.PostListPageSize; var postList = await _postService.GetPagedPostsAsync(pagesize, page); var postCount = _cache.GetOrCreate(CacheDivision.General, "postcount", entry => _postService.CountVisiblePosts()); var postsAsIPagedList = new StaticPagedList <PostListEntry>(postList, page, pagesize, postCount); return(View(postsAsIPagedList)); } catch (Exception e) { Logger.LogError(e, "Error getting post list."); return(ServerError("Error getting post list.")); } }
public async Task <IActionResult> Index(int page = 1, [FromServices] IMemoryCache memoryCache = null) { int pagesize = _blogConfig.ContentSettings.PostListPageSize; var postList = await _postService.GetPagedPostsAsync(pagesize, page); int postCount = memoryCache.GetOrCreate(StaticCacheKeys.PostCount, entry => _postService.CountVisiblePosts().Item); var postsAsIPagedList = new StaticPagedList <PostListItem>(postList, page, pagesize, postCount); return(View(postsAsIPagedList)); }