cleanup
This commit is contained in:
parent
1b910adf55
commit
af441e772b
34 changed files with 279 additions and 292 deletions
37
Sledgemapper.Api/Handlers/NewSnapshotCommandHandler.cs
Normal file
37
Sledgemapper.Api/Handlers/NewSnapshotCommandHandler.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using MediatR;
|
||||
using Sledgemapper.Api.Data;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sledgemapper.Api.Commands
|
||||
{
|
||||
public class NewSnapshotCommandHandler : IRequestHandler<NewSnapshotCommand, bool>
|
||||
{
|
||||
private readonly MyDbContext _dbcontext;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public NewSnapshotCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||
|
||||
public async Task<bool> Handle(NewSnapshotCommand notification, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
|
||||
var newSnapshot = new Sledgemapper.Api.Models.Snapshot{
|
||||
SessionId=session.SessionId,
|
||||
Timestamp=notification.Timestamp,
|
||||
Object = JsonSerializer.Serialize<Sledgemapper.Shared.Entities.Session>(notification.Session)
|
||||
|
||||
};
|
||||
await _dbcontext.Snapshots.AddAsync(newSnapshot);
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue