/// <summary> /// Remove a specified Game from a Match. /// Applies necessary affects to other, related Matches. /// Updates scores and Rankings accordingly. /// _updateInstead determines whether to notify the DB to delete the game. /// May fire events: MatchesModified, GamesDeleted. /// If Match or Game is not found, an exception is thrown. /// </summary> /// <param name="_matchNumber">Match to alter</param> /// <param name="_gameNumber">Game to remove</param> /// <param name="_updateInstead">false if removing the game, true if updating</param> /// <returns>Model of removed Game</returns> public GameModel RemoveGameNumber(int _matchNumber, int _gameNumber, bool _updateInstead = false) { Match match = GetInternalMatch(_matchNumber); MatchModel oldMatchModel = GetMatchModel(match); PlayerSlot winnerSlot = match.WinnerSlot; List <GameModel> modelList = new List <GameModel>(); // Remove the Game and update the Bracket & Rankings: modelList.Add(match.RemoveGameNumber(_gameNumber)); List <MatchModel> alteredMatches = ApplyGameRemovalEffects(_matchNumber, modelList, winnerSlot); UpdateScore(_matchNumber, modelList, false, oldMatchModel); // Fire Event with any Matches that changed: alteredMatches.Add(GetMatchModel(match)); BracketEventArgs args = null; if (_updateInstead) { args = new BracketEventArgs(alteredMatches); } else { args = new BracketEventArgs (alteredMatches, modelList.Select(g => g.GameID).ToList()); } OnMatchesModified(args); // Return a Model of the removed Game: return(modelList[0]); }
protected void OnGamesDeleted(BracketEventArgs _e) { GamesDeleted?.Invoke(this, _e); }
protected void OnRoundDeleted(BracketEventArgs _e) { RoundDeleted?.Invoke(this, _e); }
protected void OnMatchesModified(BracketEventArgs _e) { MatchesModified?.Invoke(this, _e); }
/* * The following protected methods are helpers. * They are included to simplify the firing of Bracket events. * Each helper will translate the given parameter(s) to a relevant BracketEventArgs. * If the passed list is empty, no event will be fired. * If the relevant event's subscriber-list is empty/null, no event will be fired. */ protected virtual void OnRoundAdded(BracketEventArgs _e) { RoundAdded?.Invoke(this, _e); }