using MediatR; using Sledgemapper.Api.Data; using Sledgemapper.Shared.Entities; using System.Linq; using System.Text.Json; using System.Threading; using System.Threading.Tasks; namespace Sledgemapper.Api.Handlers { public class SaveDeleteTile : INotificationHandler { private readonly MyDbContext _dbcontext; public SaveDeleteTile(MyDbContext dbcontext) => _dbcontext = dbcontext; public async Task Handle(DeleteTileNotification notification, CancellationToken cancellationToken) { var jsonString = JsonSerializer.Serialize(notification.Tile); var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName); _dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog { Operation = "D", SessionId = session.SessionId, Type = "T", Timestamp = notification.Timestamp, Object = jsonString, UserId = notification.UserId }); await _dbcontext.SaveChangesAsync(); } } }