32 lines
952 B
C#
32 lines
952 B
C#
using MediatR;
|
|
using Sledgemapper.Api.Commands;
|
|
using Sledgemapper.Api.Data;
|
|
using Sledgemapper.Api.Models;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sledgemapper.Api.Handlers
|
|
{
|
|
public class StartNewSessionHandler : IRequestHandler<NewSessionCommand, bool>
|
|
{
|
|
private readonly IMediator _mediator;
|
|
private readonly MyDbContext _dbcontext;
|
|
|
|
public StartNewSessionHandler(IMediator mediator, MyDbContext dbcontext)
|
|
{
|
|
_mediator = mediator;
|
|
_dbcontext = dbcontext;
|
|
}
|
|
|
|
public async Task<bool> Handle(NewSessionCommand notification, CancellationToken cancellationToken)
|
|
{
|
|
_dbcontext.Sessions.Add(new Session
|
|
{
|
|
SessionName = notification.SessionName,
|
|
OwnerUserId = notification.UserId
|
|
});
|
|
await _dbcontext.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
}
|
|
}
|