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

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();
}
}
}