27 lines
713 B
C#
27 lines
713 B
C#
using System;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Sports.DbContexts;
|
|
using Sports.Entities;
|
|
using Sports.Helpers;
|
|
using Sports.Queries;
|
|
|
|
namespace Sports.Handlers
|
|
{
|
|
public class GetSportsQueryHandler : IRequestHandler<GetSportsQuery, PagedList<Sport>>
|
|
{
|
|
private readonly SportsContext _dbContext;
|
|
|
|
public GetSportsQueryHandler(SportsContext dbContext)
|
|
{
|
|
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
|
}
|
|
|
|
public async Task<PagedList<Sport>> Handle(GetSportsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return PagedList<Sport>.ToPagedList(await _dbContext.Sports.ToListAsync(), request.PageNumber, request.PageSize);
|
|
}
|
|
}
|
|
}
|
|
|