31 lines
983 B
C#
31 lines
983 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 SaveDeleteTile : INotificationHandler<DeleteTileNotification>
|
|
{
|
|
private readonly MyDbContext _dbcontext;
|
|
|
|
public SaveDeleteTile(MyDbContext dbcontext) => _dbcontext = dbcontext;
|
|
|
|
public async Task Handle(DeleteTileNotification notification, CancellationToken cancellationToken)
|
|
{
|
|
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
|
|
|
|
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
|
{
|
|
Operation = "D",
|
|
SessionName = notification.SessionName,
|
|
Type = "T",
|
|
Timestamp = notification.Timestamp,
|
|
Object = jsonString
|
|
});
|
|
await _dbcontext.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|