sledgemapper/Sledgemapper.Api/Handlers/SaveNewWall.cs
2020-11-17 00:01:21 +00:00

33 lines
1.1 KiB
C#

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 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);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "N",
SessionId = session.SessionId,
Type = "W",
Timestamp = notification.Timestamp,
Object = jsonString,
UserId = notification.UserId,
});
await _dbcontext.SaveChangesAsync();
}
}
}