// Add score to a game history // 0 : no error // 1 : game or score is just initialized // 2 : game not in db // 42 : check error public int addScore(BTGame game, BTGameHistory score) { int status = 0; // Check if both Game and GameHistory objects aren't just initialized if (game.Equals(default(BTGame)) || score.Equals(default(BTGameHistory))) { status = 1; } else { bool temp_status = false; // Check if game exists in database foreach (BTGame game_in_db in database.game) { if (game_in_db.game_id == game.game_id) { temp_status = true; } } // If it exists if (temp_status == true) { try { // Adding score to database for (int i = 0; i < database.game.Count; i++) { if (database.game[i].game_id == game.game_id) { database.game[i].scores.history.Add(score); } } // Saving changes saveDatabase(); } // If something else happend catch (Exception ex) { error = ex.Message; status = 42; } } else { status = 2; } } return(status); }