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,28 @@
using System;
using Games.Commands;
using Games.DbContexts;
using Games.Entities;
using MediatR;
namespace Games.Handlers
{
public class AddGamesCommandHandler : IRequestHandler<AddGamesCommand, Unit>
{
private readonly GamesContext _dbContext;
public AddGamesCommandHandler(GamesContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<Unit> Handle(AddGamesCommand request, CancellationToken cancellationToken)
{
await _dbContext.Games.AddRangeAsync(request.games, cancellationToken);
_dbContext.SaveChanges();
return Unit.Value;
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using Games.DbContexts;
using Games.Entities;
using Games.Helpers;
using Games.Queries;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Games.Handlers
{
public class GetGameByIdQueryHandler : IRequestHandler<GetGameByIdQuery, Game>
{
private readonly GamesContext _dbContext;
public GetGameByIdQueryHandler(GamesContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<Game> Handle(GetGameByIdQuery request, CancellationToken cancellationToken)
{
return await _dbContext.Games.Where(g => g.GamePk == request.GameId).FirstOrDefaultAsync();
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using Games.DbContexts;
using Games.Entities;
using Games.Helpers;
using Games.Queries;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Games.Handlers
{
public class GetGamesQueryHandler : IRequestHandler<GetGamesQuery, PagedList<Game>>
{
private readonly GamesContext _dbContext;
public GetGamesQueryHandler(GamesContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<PagedList<Game>> Handle(GetGamesQuery request, CancellationToken cancellationToken)
{
var games = await _dbContext.Games.ToListAsync();
return PagedList<Game>.ToPagedList(await _dbContext.Games.ToListAsync(), request.PageNumber, request.PageSize);
}
}
}