Files
mlb-gameday-dotnet-react/seasons/Handlers/GetSeasonsQueryHandler.cs
2023-06-01 08:52:05 -05:00

28 lines
782 B
C#

using System;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Seasons.DbContexts;
using Seasons.Entities;
using Seasons.Helpers;
using Seasons.Queries;
namespace Seasons.Handlers
{
public class GetSeasonsQueryHandler : IRequestHandler<GetSeasonsQuery, PagedList<Season>>
{
private readonly SeasonsContext _dbContext;
public GetSeasonsQueryHandler(SeasonsContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<PagedList<Season>> Handle(GetSeasonsQuery request, CancellationToken cancellationToken)
{
var seasons = await _dbContext.Seasons.ToListAsync();
return PagedList<Season>.ToPagedList(await _dbContext.Seasons.ToListAsync(), request.PageNumber, request.PageSize);
}
}
}