27 lines
665 B
C#
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();
|
|
}
|
|
}
|
|
}
|
|
|