using System; using Leagues.DbContexts; using Leagues.Entities; using Leagues.Queries; using MediatR; using Microsoft.EntityFrameworkCore; namespace Leagues.Handlers { public class GetLeagueByIdQueryHandler : IRequestHandler { private readonly LeaguesContext _dbContext; public GetLeagueByIdQueryHandler(LeaguesContext dbContext) { _dbContext = dbContext ?? throw new ArgumentException(nameof(dbContext)); } public async Task Handle(GetLeagueByIdQuery request, CancellationToken cancellation) { return await _dbContext.Leagues.Where(l => l.Id == request.LeagueId).FirstOrDefaultAsync(); } } }