32 lines
990 B
C#
32 lines
990 B
C#
using MediatR;
|
|
using Sledgemapper.Api.Data;
|
|
using Sledgemapper.Shared.Entities;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sledgemapper.Api.Handlers
|
|
{
|
|
public class SaveNewOverlay : INotificationHandler<NewOverlayNotification>
|
|
{
|
|
private readonly MyDbContext _dbcontext;
|
|
|
|
public SaveNewOverlay(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
|
|
|
public async Task Handle(NewOverlayNotification notification, CancellationToken cancellationToken)
|
|
{
|
|
var jsonString = JsonSerializer.Serialize<Overlay>(notification.Overlay);
|
|
|
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
|
{
|
|
Operation = "N",
|
|
SessionName = notification.SessionName,
|
|
Type = "O",
|
|
Timestamp = notification.Timestamp,
|
|
Object = jsonString
|
|
});
|
|
|
|
await _dbcontext.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|