29 lines
637 B
C#
29 lines
637 B
C#
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;
|
|
}
|
|
}
|
|
}
|
|
|