Esempio n. 1
0
        public async Task<GetPostListOutput> GetPostsByPage(GetPostListInput input)
        {
            //跳过条数
            var skipCount = (input.PageIndex - 1) * input.PageSize;
            //获取条数
            var maxResultCount = input.PageSize;

            //获取总条数
            var totalCount = await _postRepository.CountAsync();
            //获取当前页的数据
            var items = await this._postRepository.GetEnumerableByPage(skipCount, maxResultCount, w => true, o => o.CreationTime);

            //稍微处理一下结果集
            items = items.Select(w => new Post
            {
                Id = w.Id,
                Title = w.Title,
                EntryName = w.EntryName,
                Status = w.Status,
                PVCount = w.PVCount
            });

            return  new GetPostListOutput
            {
                Items = Mapper.Map<IReadOnlyList<PostDto>>(items),
                TotalCount = totalCount,
                PageIndex = input.PageIndex
    };
}
Esempio n. 2
0
public async Task<GetPostListOutput> PostList(GetPostListInput input)
{
    //跳过条数
    var skipCount = (input.PageIndex - 1) * input.PageSize;
    //获取条数
    var maxResultCount = input.PageSize;

    //获取总条数
    var totalCount = await _postRepository.CountAsync();
    //获取当前页的数据
    var items = await this._postRepository.GetEnumerableByPage(skipCount, maxResultCount, w => w.Status == PostState.Publish, o => o.IsTop, o => o.CreationTime);

    return new GetPostListOutput
    {
        Items = Mapper.Map<IReadOnlyList<PostDto>>(items),
        TotalCount = totalCount,
        PageIndex = input.PageIndex
    };
}