private GameDbModel CreateGameDbModelMock(Game game) { var gameDbModel = new GameDbModel() { Name = game.Name, GameJson = _sut.Serialize(game) }; return(gameDbModel); }
private Game Deserialize(GameDbModel game) { var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; return(JsonSerializer.Deserialize <Game>(game.GameJson, options)); }
public Game GetGame(string name) { string lowName = name.ToLower(); GameDbModel gameDbModel = _ctx.Find <GameDbModel>(lowName); if (gameDbModel == null) { return(null); } return(Deserialize(gameDbModel)); }
private void SaveGame(Game game) { GameDbModel gameDbModel = _ctx.Find <GameDbModel>(game.Name); if (gameDbModel == null) { gameDbModel = new GameDbModel() { LastUpdated = DateTime.Now, Name = game.Name.ToLower(), GameJson = Serialize(game) }; _ctx.ShitheadGames.Add(gameDbModel); } else { gameDbModel.LastUpdated = DateTime.Now; gameDbModel.GameJson = Serialize(game); } _ctx.SaveChanges(); }
public static Game FromSnapshot(GameDbModel snapshot) { var game = new Game { Id = snapshot.Id, Name = snapshot.Name, _hasStarted = snapshot.HasStarted, _hasEnded = false, Winner = null, Board = Board.FromStanpshot(snapshot.Board) }; if (snapshot.BlackPlayerId.HasValue) { game._players.Add(snapshot.BlackPlayerId.Value, Player.Create(snapshot.BlackPlayerId.Value, snapshot.BlackPlayerName, PawnColor.Black)); } if (snapshot.WhitePlayerId.HasValue) { game._players.Add(snapshot.WhitePlayerId.Value, Player.Create(snapshot.WhitePlayerId.Value, snapshot.WhitePlayerName, PawnColor.White)); } return(game); }
public async Task Update(GameDbModel game) { await _games.ReplaceOneAsync(x => x.Id == game.Id, game); }
public async Task Add(GameDbModel game) { await _games.InsertOneAsync(game); }