phronCare/Models/Helpers/PaginationExtensions.cs
Leandro Hernan Rojas 3962d889fd
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m23s
Add Pagination in API Customer
2025-04-06 01:19:47 -03:00

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
};
}
}
}