Major update
This commit is contained in:
25
sports/Handlers/GetSportByIdQueryHandler.cs
Normal file
25
sports/Handlers/GetSportByIdQueryHandler.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
sports/Handlers/GetSportsQueryHandler.cs
Normal file
26
sports/Handlers/GetSportsQueryHandler.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sports.DbContexts;
|
||||
using Sports.Entities;
|
||||
using Sports.Helpers;
|
||||
using Sports.Queries;
|
||||
|
||||
namespace Sports.Handlers
|
||||
{
|
||||
public class GetSportsQueryHandler : IRequestHandler<GetSportsQuery, PagedList<Sport>>
|
||||
{
|
||||
private readonly SportsContext _dbContext;
|
||||
|
||||
public GetSportsQueryHandler(SportsContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
|
||||
}
|
||||
|
||||
public async Task<PagedList<Sport>> Handle(GetSportsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return PagedList<Sport>.ToPagedList(await _dbContext.Sports.ToListAsync(), request.PageNumber, request.PageSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user