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

27 lines
665 B
C#

using System;
using Games.DbContexts;
using Games.Entities;
using Games.Helpers;
using Games.Queries;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Games.Handlers
{
public class GetGameByIdQueryHandler : IRequestHandler<GetGameByIdQuery, Game>
{
private readonly GamesContext _dbContext;
public GetGameByIdQueryHandler(GamesContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<Game> Handle(GetGameByIdQuery request, CancellationToken cancellationToken)
{
return await _dbContext.Games.Where(g => g.GamePk == request.GameId).FirstOrDefaultAsync();
}
}
}