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