Files
mlb-gameday-dotnet-react/games/Handlers/AddGamesCommandHandler.cs
2023-06-01 08:52:05 -05:00

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