private async Task CheckGameName(Game existingGame, Game game) { if (!existingGame.GameName.Equals(game.GameName)) { var filter = Builders <Game> .Filter.Eq(x => x.Id, existingGame.Id); var update = Builders <Game> .Update.Set(x => x.GameName, game.GameName); await _gameCollection.UpdateOneAsync(filter, update); OnGameAction?.Invoke(this, new GameEventArgs("The game name has changed.", game)); } }
private async Task CheckForChanges(Game game) { var filter = Builders <Game> .Filter.Eq(x => x.Id, game.Id); var dbGame = (await _gameCollection.FindAsync(filter)).FirstOrDefault(); // A new game that does not exist yet if (dbGame == null) { // Add the game to the db await _gameCollection.InsertOneAsync(game); OnGameAction?.Invoke(this, new GameEventArgs("New game scheduled.", game)); return; } await CheckGameName(dbGame, game); await CheckGameActivity(dbGame, game); await CheckGameNote(dbGame, game); await CheckGameStartTime(dbGame, game); await CheckPlayersJoined(dbGame, game); await CheckPlayersLeft(dbGame, game); }