I don't know what I'm doing anymore
This commit is contained in:
parent
ea9cc32534
commit
8fdee0cb67
17 changed files with 342 additions and 116 deletions
19
Sledgemapper.Api/Commands/BaseCommand.cs
Normal file
19
Sledgemapper.Api/Commands/BaseCommand.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using MediatR;
|
||||
using System;
|
||||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public abstract class BaseCommand<T> : IRequest<T>
|
||||
{
|
||||
public double Timestamp { get; private set; }
|
||||
public string SessionName { get; private set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public BaseCommand(string sessionName, int userId)
|
||||
{
|
||||
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
SessionName = sessionName;
|
||||
UserId=userId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,14 +2,10 @@ using MediatR;
|
|||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public class NewSessionCommand : IRequest<bool>
|
||||
public class NewSessionCommand : BaseCommand<bool>
|
||||
{
|
||||
public string SessionName { get; set; }
|
||||
public int UserId { get; }
|
||||
public NewSessionCommand(string sessionName, int userId)
|
||||
public NewSessionCommand(string sessionName, int userId):base(sessionName, userId)
|
||||
{
|
||||
SessionName = sessionName;
|
||||
UserId = userId;
|
||||
}
|
||||
}
|
||||
}
|
47
Sledgemapper.Api/Commands/SaveNewTileCommand.cs
Normal file
47
Sledgemapper.Api/Commands/SaveNewTileCommand.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System.Transactions;
|
||||
using System.Net.Mail;
|
||||
using MediatR;
|
||||
using Sledgemapper.Api.Data;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Sledgemapper.Api.Handlers;
|
||||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public class SaveNewTileCommand:BaseCommand<bool>
|
||||
{
|
||||
public Tile Tile {get;set;}
|
||||
public SaveNewTileCommand(string sessionName, Tile tile, int userId):base(sessionName, userId){
|
||||
Tile=tile;
|
||||
}
|
||||
}
|
||||
|
||||
public class SaveNewTileCommandHandler : IRequestHandler<SaveNewTileCommand, bool>
|
||||
{
|
||||
private readonly MyDbContext _dbcontext;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public SaveNewTileCommandHandler(IMediator mediator, MyDbContext dbcontext){ _dbcontext = dbcontext; _mediator= mediator;}
|
||||
|
||||
public async Task<bool> Handle(SaveNewTileCommand notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
|
||||
|
||||
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
|
||||
{
|
||||
Operation = "N",
|
||||
SessionName = notification.SessionName,
|
||||
Type = "T",
|
||||
Timestamp = notification.Timestamp,
|
||||
Object = jsonString
|
||||
});
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
await _mediator.Publish(new NewTileNotification(notification.SessionName, notification.Tile));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue