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

26 lines
640 B
C#

using System;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Teams.DbContexts;
using Teams.Entities;
using Teams.Queries;
namespace Teams.Handlers
{
public class GetTeamByIdQueryHandler : IRequestHandler<GetTeamByIdQuery, Team>
{
private readonly TeamsContext _dbContext;
public GetTeamByIdQueryHandler(TeamsContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<Team> Handle(GetTeamByIdQuery request, CancellationToken cancellationToken)
{
return await _dbContext.Teams.Where(x => x.Id == request.TeamId).FirstOrDefaultAsync();
}
}
}