funziona
This commit is contained in:
parent
0a4b8ebeb2
commit
e988f5c310
13 changed files with 135 additions and 72 deletions
|
@ -34,10 +34,10 @@ namespace Sledgemapper.Api.Commands
|
|||
double timestamp;
|
||||
Sledgemapper.Shared.Entities.Session mapSession;
|
||||
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||
snapshot = _dbcontext.Snapshots.FirstOrDefault(m => m.SessionId == session.SessionId);
|
||||
snapshot = _dbcontext.Snapshots.OrderByDescending(s => s.Timestamp).FirstOrDefault(m => m.SessionId == session.SessionId);
|
||||
if (snapshot is null)
|
||||
{
|
||||
|
||||
|
||||
timestamp = 0;
|
||||
mapSession = new Shared.Entities.Session();
|
||||
}
|
||||
|
@ -59,11 +59,11 @@ namespace Sledgemapper.Api.Commands
|
|||
mapSession.NewTile(tile, tile.ID);
|
||||
break;
|
||||
case "W":
|
||||
var wall = JsonSerializer.Deserialize<Wall>(mapUpdate.Object);
|
||||
var wall = JsonSerializer.Deserialize<Wall>(mapUpdate.Object);
|
||||
mapSession.NewWall(wall, wall.ID);
|
||||
break;
|
||||
case "O":
|
||||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
mapSession.NewOverlay(overlay, overlay.ID);
|
||||
break;
|
||||
|
||||
|
@ -79,24 +79,29 @@ namespace Sledgemapper.Api.Commands
|
|||
mapSession.DeleteTile(tile);
|
||||
break;
|
||||
case "W":
|
||||
var wall = JsonSerializer.Deserialize<Wall>(mapUpdate.Object);
|
||||
var wall = JsonSerializer.Deserialize<Wall>(mapUpdate.Object);
|
||||
mapSession.DeleteWall(wall);
|
||||
break;
|
||||
case "O":
|
||||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
|
||||
mapSession.DeleteOverlay(overlay);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
var newSnapshot = new Snapshot{
|
||||
SessionId=session.SessionId,
|
||||
Timestamp=mapUpdates.Max(mapSession=>mapSession.Timestamp),
|
||||
Object = JsonSerializer.Serialize<Sledgemapper.Shared.Entities.Session>(mapSession)
|
||||
if (mapUpdates.Any())
|
||||
{
|
||||
var newSnapshot = new Snapshot
|
||||
{
|
||||
SessionId = session.SessionId,
|
||||
Timestamp = mapUpdates.Max(mapSession => mapSession.Timestamp),
|
||||
Object = JsonSerializer.Serialize<Sledgemapper.Shared.Entities.Session>(mapSession)
|
||||
};
|
||||
await _dbcontext.Snapshots.AddAsync(newSnapshot);
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
await _dbcontext.Snapshots.AddAsync(newSnapshot);
|
||||
await _dbcontext.SaveChangesAsync();
|
||||
|
||||
|
||||
return mapSession;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue