37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using MediatR;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Sledgemapper.Api.Data;
|
|
using Sledgemapper.Shared.Entities;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sledgemapper.Api.Handlers
|
|
{
|
|
|
|
public class SaveDeleteWall : INotificationHandler<DeleteWallNotification>
|
|
{
|
|
private readonly MyDbContext _dbcontext;
|
|
|
|
public SaveDeleteWall(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
|
|
|
public async Task Handle(DeleteWallNotification notification, CancellationToken cancellationToken)
|
|
{
|
|
var jsonString = JsonSerializer.Serialize<Wall>(notification.Wall);
|
|
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
|
|
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
|
{
|
|
Operation = "D",
|
|
SessionId = session.SessionId,
|
|
Type = "W",
|
|
Timestamp = notification.Timestamp,
|
|
Object = jsonString,
|
|
UserId = notification.UserId
|
|
});
|
|
await _dbcontext.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|