private void AddGame(SavedGameInfo gameInfo) { var users = PersistanceManager.GetCollection(); var x = users.UpdateOneAsync( Builders <BsonDocument> .Filter.Eq("name", Name), Builders <BsonDocument> .Update.Push("savedGames", gameInfo.ToBsonDoc()) ).Result; SavedGames.Add(gameInfo); }
public void DeleteGame(SavedGameInfo gameInfo) { var users = PersistanceManager.GetCollection(); var x = users.UpdateOneAsync( Builders <BsonDocument> .Filter.Eq("name", Name), Builders <BsonDocument> .Update.Pull("savedGames", new BsonDocument { { "id", gameInfo.Id } }) ).Result; SavedGames.RemoveAll(g => g.Id == gameInfo.Id); }
private static BsonDocument GetUserBson(string name) { var filter = Builders <BsonDocument> .Filter.Eq("name", name); using (var cursor = PersistanceManager.GetCollection().FindAsync(filter).Result) { while (cursor.MoveNextAsync().Result) { var batch = cursor.Current; foreach (var document in batch) { return(document); } } } return(null); }
public static User NewUser(string userName, string pwd) { var existingUser = GetUser(userName); if (existingUser != null) { throw new ArgumentException("username used"); } var user = new User(userName, pwd); var users = PersistanceManager.GetCollection(); var x = users.InsertOneAsync( new BsonDocument { { "name", userName }, { "pwd", pwd }, { "savedGames", new BsonArray() } } ); return(user); }