29 lines
749 B
C#
29 lines
749 B
C#
using System;
|
|
using Games.DbContexts;
|
|
using Games.Entities;
|
|
using Games.Helpers;
|
|
using Games.Queries;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Games.Handlers
|
|
{
|
|
public class GetGamesQueryHandler : IRequestHandler<GetGamesQuery, PagedList<Game>>
|
|
{
|
|
private readonly GamesContext _dbContext;
|
|
|
|
public GetGamesQueryHandler(GamesContext dbContext)
|
|
{
|
|
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
|
}
|
|
|
|
public async Task<PagedList<Game>> Handle(GetGamesQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var games = await _dbContext.Games.ToListAsync();
|
|
|
|
return PagedList<Game>.ToPagedList(await _dbContext.Games.ToListAsync(), request.PageNumber, request.PageSize);
|
|
}
|
|
}
|
|
}
|
|
|