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