28 lines
791 B
C#
28 lines
791 B
C#
using System;
|
|
using Leagues.DbContexts;
|
|
using Leagues.Entities;
|
|
using Leagues.Helpers;
|
|
using Leagues.Queries;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Leagues.Handlers
|
|
{
|
|
public class GetLeaguesQueryHandler : IRequestHandler<GetLeaguesQuery, PagedList<League>>
|
|
{
|
|
private readonly LeaguesContext _dbContext;
|
|
|
|
public GetLeaguesQueryHandler(LeaguesContext dbContext)
|
|
{
|
|
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
|
}
|
|
|
|
public async Task<PagedList<League>> Handle(GetLeaguesQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var leagues = await _dbContext.Leagues.ToListAsync();
|
|
return PagedList<League>.ToPagedList(await _dbContext.Leagues.ToListAsync(), request.PageNumber, request.PageSize);
|
|
}
|
|
}
|
|
}
|
|
|