WGShare.API/WGShare.Domain/GeneralModel/PagedResult.cs

39 lines
974 B
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace WGShare.Domain.GeneralModel
{
/// <summary>
/// 统一分页返回结果模型
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public class PagedResult<TEntity>
{
public PagedResult() { }
public PagedResult(IEnumerable<TEntity> list, int total, int pageSize = 10)
{
Total = total;
Items = list;
}
public int Total { get; set; }
public IEnumerable<TEntity> Items { get; private set; }
private int pageSize = 10;
public int TotalPage
{
get
{
return (int)Math.Ceiling(Total / (double)pageSize);
}
}
public static PagedResult<TEntity> Create(IEnumerable<TEntity> list, int total, int pageSize = 10)
{
return new PagedResult<TEntity>(list, total, pageSize);
}
}
}