/// <summary> /// Resets every round after the given round index. /// This removes the Players from every affected Match, /// in addition to resetting their Games and scores. /// Will NOT remove the Players from round 1, even if passed a 0. /// Sets ActiveRound to the given round index. /// May fire MatchesModified and GamesDeleted events, if updates occur. /// If _currentRoundIndex is out of range, nothing is modified. /// </summary> /// <param name="_currentRoundIndex">Reset all rounds after this index</param> /// <returns>List of Models of altered Matches</returns> private List <MatchModel> RemoveFutureRounds(int _currentRoundIndex) { List <MatchModel> clearedMatches = new List <MatchModel>(); List <int> deletedGameIDs = new List <int>(); int nextRoundIndex = 1 + _currentRoundIndex; if (nextRoundIndex > NumberOfRounds) { // Recursive exit: we've reached the final round. return(clearedMatches); } // Recursive call on all rounds after this one: clearedMatches.AddRange(RemoveFutureRounds(nextRoundIndex)); if (_currentRoundIndex >= 0) { // Reset all Matches in this round: List <IMatch> nextRound = GetRound(nextRoundIndex); foreach (Match match in nextRound) { if (!(match.Players.Contains(null)) || match.Games.Count > 0 || match.IsManualWin) { deletedGameIDs.AddRange(match.Games.Select(g => g.Id)); if (nextRoundIndex > 1) { // Remove the Players (and reset score & Games): match.ResetPlayers(); } else { // Keep Players if Round = 1 (still reset score): match.ResetScore(); } // Save a Model of the updated Match: clearedMatches.Add(GetMatchModel(match)); } } if (nextRoundIndex > 1) { // For all rounds after 1, // delete associated Matchups and Bye: Matchups.RemoveAll(m => m.RoundNumber == nextRoundIndex); if (PlayerByes.Count == nextRoundIndex) { // Remove the last Bye in the list: PlayerByes.RemoveAt(PlayerByes.Count - 1); } // Update bracket Properties: ActiveRound = _currentRoundIndex; } // Fire notification event: Games were deleted. OnGamesDeleted(deletedGameIDs); } // Return a list of modified MatchModels: return(clearedMatches); }