namespace SafeCampus.Core;
///
/// 全局分页查询输入参数
///
public class BasePageInput : IValidatableObject
{
///
/// 当前页码
///
[DataValidation(ValidationTypes.Numeric)]
public virtual int PageNum { get; set; } = 1;
///
/// 每页条数
///
[Range(1, 1000, ErrorMessage = "页码容量超过最大限制")]
[DataValidation(ValidationTypes.Numeric)]
public virtual int PageSize { get; set; } = 10;
///
/// 排序字段
///
public virtual string SortField { get; set; }
///
/// 排序方式,升序:ascend;降序:descend"
///
public virtual string SortOrder { get; set; } = "desc";
///
/// 关键字
///
public virtual string SearchKey { get; set; }
public IEnumerable Validate(ValidationContext validationContext)
{
//配合小诺排序参数
if (SortOrder == "descend")
{
SortOrder = "desc";
}
else if (SortOrder == "ascend")
{
SortOrder = "asc";
}
if (!string.IsNullOrEmpty(SortField))
{
//分割排序字段
var fields = SortField.Split(" ");
if (fields.Length > 1)
{
yield return new ValidationResult("排序字段错误", new[]
{
nameof(SortField)
});
}
}
}
}