This commit is contained in:
Michele Scandura 2020-11-18 11:09:26 +00:00
parent 1b910adf55
commit af441e772b
34 changed files with 279 additions and 292 deletions

View file

@ -0,0 +1,45 @@
using MediatR;
using Microsoft.AspNetCore.Http.Features;
using Sledgemapper.Api.Data;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Notifications;
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 DeleteWallCommandHandler : IRequestHandler<DeleteWallCommand, bool>
{
private readonly MyDbContext _dbcontext;
private readonly IMediator _mediator;
public DeleteWallCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(DeleteWallCommand 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();
await _mediator.Publish(new DeleteWallNotification(session, notification.Wall, notification.UserId));
return true;
}
}
}