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