public static void UpdateTournamentRound(this TournamentModel tournament, RoundModel round) { bool roundCompleted = round.Matchups.All(m => m.Winner != null); if (!roundCompleted) { throw new Exception("Winners have not been assigned to matchups in this round"); } round.Active = false; GlobalConfig.Connection.UpdateRound(round); bool isFinalRound = tournament.Rounds.Count == round.Number; if (!isFinalRound) { RoundModel nextRound = tournament.Rounds.First(r => r.Number == round.Number + 1); nextRound.Active = true; nextRound.Matchups.ForEach(m => m.Entries.ForEach(me => { me.TeamCompeting = me.ParentMatchup.Winner; GlobalConfig.Connection.UpdateMatchupEntry(me); })); GlobalConfig.Connection.UpdateRound(nextRound); tournament.NotifyEnteredTeams(nextRound); } else { tournament.CompleteTournament(); tournament.NotifyTournamentComplete(); } }