using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace zzz.Model
{
///
/// 通用分页信息类
///
public class PageModel
{
///
/// 当前页标
///
public int pageIndex { get; set; } = 1;
///
/// 每页大小
///
public int pageSize { set; get; } = 20;
///
/// 总页数
///
public int totalPages => (int)Math.Ceiling((decimal)totalCount / pageSize);
///
/// 数据总数
///
public int totalCount { get; set; } = 0;
///
/// 返回数据
///
public List rows { get; set; }
///
///
///
public PageModel() { }
///
///
///
///
///
///
///
public PageModel(int pageIndex, int totalCount, int pageSize, List rows)
{
this.pageIndex = pageIndex;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.rows = rows;
}
///
///
///
///
///
//private PageModel ConvertTo()
//{
// return new PageModel(pageIndex, totalCount, pageSize, default);
//}
///
///
///
///
///
public PageModel ConvertTo()
{
var model = new PageModel(pageIndex, totalCount, pageSize, default);
if (rows != null)
{
var cfg = new MapperConfiguration(cfg => cfg.CreateMap());
var m = cfg.CreateMapper();
model.rows = m.Map>(rows);
}
return model;
}
///
///
///
///
///
///
public PageModel ConvertTo(Action options)
{
var model = new PageModel(pageIndex, totalCount, pageSize, default);
if (rows != null)
{
var cfg = new MapperConfiguration(cfg => cfg.CreateMap());
var m = cfg.CreateMapper();
model.rows = m.Map>(rows, options);
}
return model;
}
}
}