public async Task <Paged <Role> > PagingAsync(ContextModel context, Paging paging)
{
var paged = await Query
.Query(
filter : (items) =>
{
items = items.QueryByPermission(context);
items = items.QueryByDeletedBy();
if (!string.IsNullOrEmpty(paging.Q))
{
var q = paging.Q.ToUpper();
items = items.Where(x => x.NormalizedName.Contains(q));
}
if (paging.Search != null)
{
foreach (var item in paging.Search)
{
items = items.Contains(item.Key, item.Value);
}
}
if (paging.Sort != null)
{
items = items.OrderBy(paging.Sort);
}
if (paging.Columns != null)
{
items = items.Select(paging.Columns
.Where(x => x.Value)
.Select(x => x.Key)
.ToArray());
}
return(items);
},
order : x => x.OrderByDescending(y => y.CreatedAt),
include : null)
.ToPaginationAsync(paging);
return(paged);
}