Max page size (#9)

This commit is contained in:
Biarity 2018-02-15 18:45:19 +10:00
parent af1fa00fb1
commit 69f21ca695
2 changed files with 4 additions and 1 deletions

View File

@ -11,6 +11,8 @@ namespace Sieve.Models
public int DefaultPageSize { get; set; } = 0;
public int MaxPageSize { get; set; } = 0;
public bool ThrowExceptions { get; set; } = false;
}
}

View File

@ -239,11 +239,12 @@ namespace Sieve.Services
{
var page = model?.Page ?? 1;
var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize;
var maxPageSize = _options.Value.MaxPageSize > 0 ? _options.Value.MaxPageSize : pageSize;
result = result.Skip((page - 1) * pageSize);
if (pageSize > 0)
result = result.Take(pageSize);
result = result.Take(Math.Min(pageSize, maxPageSize));
return result;
}