Major update
This commit is contained in:
27
leagues/Handlers/GetLeaguesQueryHandler.cs
Normal file
27
leagues/Handlers/GetLeaguesQueryHandler.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user