public async Task SaveData <TData>(string key, TData data, CancellationToken cancellationToken) { await using var context = contextFactory.CreateDbContext(); var dataEntity = await FindSessionData(context, key, cancellationToken); var serializedData = SerializeData(data); if (dataEntity != null) { dataEntity.Data = serializedData; context.Update(dataEntity); } else { dataEntity = new SessionDataEntity { Key = key, Data = serializedData, }; await context.AddAsync(dataEntity, cancellationToken); } await context.SaveChangesAsync(cancellationToken); }
public SessionDataEntity ConnectNewPlayerToSession(SessionDataEntity body) { if (sessionList.Find(x => x.SessionName == body.SessionName) == null) { throw new InvalidOperationException("Could not find Session"); } var session = sessionList.Find(x => x.SessionName == body.SessionName); PlayerEntity player = new PlayerEntity() { PlayerId = Guid.NewGuid() }; session.PlayerList.Add(player); body.SessionId = session.SessionId; body.Player = player; return(body); }
public SessionDataEntity UpdatePlayerInSession(SessionDataEntity body) { if (sessionList.Find(x => x.SessionName == body.SessionName) == null) { throw new InvalidOperationException("Could not find Session"); } var session = sessionList.Find(x => x.SessionName == body.SessionName); if (session.PlayerList.Find(x => x.PlayerId == body.Player.PlayerId) == null) { throw new InvalidOperationException("Could not find Session"); } var player = session.PlayerList.Find(x => x.PlayerId == body.Player.PlayerId); player.PlayerName = body.Player.PlayerName; body.Player = player; return(body); }
public string HandleGet(SessionDataEntity body) { throw new NotImplementedException(); }