26 lines
654 B
C#
26 lines
654 B
C#
using System;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Sports.DbContexts;
|
|
using Sports.Entities;
|
|
using Sports.Queries;
|
|
|
|
namespace Sports.Handlers
|
|
{
|
|
public class GetSportByIdQueryHandler : IRequestHandler<GetSportByIdQuery, Sport>
|
|
{
|
|
private readonly SportsContext _dbContext;
|
|
|
|
public GetSportByIdQueryHandler(SportsContext dbContext)
|
|
{
|
|
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
|
}
|
|
|
|
public async Task<Sport> Handle(GetSportByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _dbContext.Sports.Where(s => s.Id == request.SportId).FirstOrDefaultAsync();
|
|
}
|
|
}
|
|
}
|
|
|