Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ExtensionsQueries.cs
- namespace HICE.Domain.Core.ExtensionMethods
- {
- public static class ExtensionsQueries
- {
- /// <summary>
- /// Generate Paginated List
- /// </summary>
- /// <typeparam name="T">Entidade</typeparam>
- /// <param name="query">Query</param>
- /// <param name="initialPage">Página Inicial (Valor Padrão => [ 0 ])</param>
- /// <param name="recordsPerPage">Quantidade de Registros por Página (Valor Padrão => [ 50 ])</param>
- /// <returns>Retorna uma lista paginada</returns>
- public static IQueryable<T> Pagination<T>(this IQueryable<T> query, int initialPage = 0, int recordsPerPage = 50)
- {
- return query.Skip(initialPage * recordsPerPage).Take(recordsPerPage);
- }
- }
- // Service.cs
- namespace HICE.Domain.Services
- {
- public abstract class Service<TEntity> : AbstractValidator<TEntity>, IService<TEntity> where TEntity : Entity<TEntity>
- {
- private readonly IDomainNotificationHandler _dnh;
- private readonly IRepository<TEntity> _repository;
- public Service(IRepository<TEntity> repository, IDomainNotificationHandler dnh)
- {
- _repository = repository;
- _dnh = dnh;
- }
- public IEnumerable<TEntity> GetAll()
- {
- var obj = _repository.GetAll()
- .OrderByDescending(x => x.GetType().GetProperty(typeof(TEntity).Name + "Id"));
- return obj.Pagination();
- }
- }
- // ClienteService.cs
- namespace HICE.Domain.Services
- {
- public class ClienteService : Service<Cliente>, IClienteService
- {
- private readonly IClienteRepository _clienteRepository;
- public ClienteService(IClienteRepository clienteRepository, IDomainNotificationHandler dnh)
- : base(clienteRepository, dnh)
- {
- _clienteRepository = clienteRepository;
- }
- }
Add Comment
Please, Sign In to add comment