All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m23s
34 lines
849 B
C#
34 lines
849 B
C#
using Domain.Generics;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Models.Helpers
|
|
{
|
|
public static class PaginationExtensions
|
|
{
|
|
public static async Task<PagedResult<T>> ToPagedResultAsync<T>(
|
|
this IQueryable<T> query,
|
|
int page,
|
|
int pageSize)
|
|
{
|
|
var totalItems = await query.CountAsync();
|
|
var items = await query
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToListAsync();
|
|
|
|
return new PagedResult<T>
|
|
{
|
|
Items = items,
|
|
TotalItems = totalItems,
|
|
Page = page,
|
|
PageSize = pageSize
|
|
};
|
|
}
|
|
}
|
|
}
|