working base entities creation
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
454c507b2f
commit
4fd77a1f17
22 changed files with 260 additions and 356 deletions
|
@ -1,8 +1,6 @@
|
|||
using MediatR;
|
||||
using Sledgemapper.Api.Infrastructure.Data;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -10,29 +8,18 @@ using Sledgemapper.Api.Notifications;
|
|||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class NewLineCommandHandler : IRequestHandler<NewLineCommand, bool>
|
||||
public class NewLineCommandHandler : BaseCommandHandler<NewLineCommand, bool>
|
||||
{
|
||||
private readonly SledgemapperDbContext _dbcontext;
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public NewLineCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
public async Task<bool> Handle(NewLineCommand notification, CancellationToken cancellationToken)
|
||||
public NewLineCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext) : base(mediator, dbcontext)
|
||||
{
|
||||
var jsonString = JsonSerializer.Serialize(notification.Line);
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
_dbcontext.MapLogs.Add(new Models.MapLog
|
||||
{
|
||||
Operation = "N",
|
||||
SessionId = session.SessionId,
|
||||
Type = "L",
|
||||
Timestamp = notification.Timestamp,
|
||||
Object = jsonString,
|
||||
UserId = notification.UserId,
|
||||
});
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
await _mediator.Publish(new NewLineNotification(session, notification.Line, notification.UserId));
|
||||
}
|
||||
|
||||
public override async Task<bool> Handle(NewLineCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
await CheckAuthorization(command);
|
||||
var jsonString = JsonSerializer.Serialize(command.Line);
|
||||
var session = await SaveLog(command, "N", "L", jsonString, cancellationToken);
|
||||
await Mediator.Publish(new NewLineNotification(session, command.Line, command.UserId), cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue