public async Task <IActionResult> List([FromServices] GetPostsQuery getPostQuery, string categoryCode = null, int page = 1) { if (page < 1) { page = 1; } IQueryable <Post> query = getPostQuery.ForCategory(categoryCode).Build(); double pagesCount = Math.Ceiling((double)query.Count() / postsPerPage); List <Data.Post> posts = await query.Paginate((page - 1) *postsPerPage, postsPerPage).ToListAsync(); var model = new PostsListModel { Posts = posts, CurrentPageIndex = page, TotalPageNumber = pagesCount }; return(Json(model)); }
public async Task <IActionResult> AllPosts([FromServices] GetPostsQuery query, string categoryCode = null) { System.Collections.Generic.List <Post> posts = await query.ForCategory(categoryCode).WithUnpublish().Build().ToListAsync(); return(Json(posts)); }