Major update

This commit is contained in:
2023-06-01 08:52:05 -05:00
parent d7c0f373f4
commit df84287eb2
264 changed files with 8614 additions and 964 deletions

View 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();
}
}
}

View 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);
}
}
}