This commit is contained in:
parent
e18cbb157c
commit
155cb4ea9a
13 changed files with 99 additions and 58 deletions
|
@ -7,6 +7,8 @@ using System.Linq;
|
|||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
|
@ -18,21 +20,32 @@ namespace Sledgemapper.Api.Handlers
|
|||
|
||||
public NewOverlayCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
public async Task<bool> Handle(NewOverlayCommand notification, CancellationToken cancellationToken)
|
||||
public async Task<bool> Handle(NewOverlayCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var jsonString = JsonSerializer.Serialize(notification.Overlay);
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
_dbcontext.Attach(user);
|
||||
|
||||
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == new Guid(command.Campaign) && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
|
||||
|
||||
var maps = campaign.Maps.Any(s => s.SessionId == int.Parse(command.SessionName));
|
||||
if (!maps)
|
||||
{
|
||||
throw new Exception("Unauthorized");
|
||||
}
|
||||
|
||||
var jsonString = JsonSerializer.Serialize(command.Overlay);
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionId == int.Parse(command.SessionName));
|
||||
_dbcontext.MapLogs.Add(new Models.MapLog
|
||||
{
|
||||
Operation = "N",
|
||||
SessionId = session.SessionId,
|
||||
Type = "O",
|
||||
Timestamp = notification.Timestamp,
|
||||
Timestamp = command.Timestamp,
|
||||
Object = jsonString,
|
||||
UserId = notification.UserId,
|
||||
UserId = command.UserId,
|
||||
});
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
await _mediator.Publish(new NewOverlayNotification(session, notification.Overlay, notification.UserId));
|
||||
await _mediator.Publish(new NewOverlayNotification(session, command.Overlay, command.UserId));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue