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