public List <ITeam> getAllTeams()
        {
            var allTeams       = TeamsTable.GetAll(dbConn);
            var allTeamMembers = TeamMembersTable.GetAll(dbConn);
            var allPersons     = PersonsTable.GetAll(dbConn);

            foreach (var team in allTeams)
            {
                var members = allTeamMembers.Where(x => x.TeamId == team.TeamId);
                foreach (var person in members)
                {
                    var thePersonRecord = allPersons.Where(x => x.PersonId == person.PersonId).First();
                    team.TeamMembers.Add(thePersonRecord);
                }
            }

            return(allTeams);
        }
        public ITournament getTournament(int id)
        {
            var tournament           = TournamentTable.Get(id, dbConn);
            var allRounds            = RoundsTable.GetAll(dbConn);
            var allMatchups          = MatchupsTable.GetAll(dbConn);
            var allMatchupEntries    = MatchupEntriesTable.GetAll(dbConn);
            var allTournamentEntries = TournamentEntryTable.GetAll(dbConn);
            var allTeams             = TeamsTable.GetAll(dbConn);
            var allTeamMembers       = TeamMembersTable.GetAll(dbConn);
            var allPersons           = PersonsTable.GetAll(dbConn);
            var allTournamentPrizes  = TournamentPrizesTable.GetAll(dbConn);

            tournament.TournamentEntries = allTournamentEntries.Where(x => x.TournamentId == tournament.TournamentId).ToList();
            tournament.TournamentPrizes  = allTournamentPrizes.Where(x => x.TournamentId == tournament.TournamentId).ToList();

            foreach (var entry in tournament.TournamentEntries)
            {
                var entryMembers = allTeamMembers.Where(x => x.TeamId == entry.TeamId).ToList();
                foreach (var member in entryMembers)
                {
                    entry.Members.Add(allPersons.Find(x => x.PersonId == member.PersonId));
                }
                var theTeam = allTeams.Where(x => x.TeamId == entry.TeamId).First();
                tournament.Teams.Add(theTeam);
            }
            tournament.Rounds = allRounds.Where(x => x.TournamentId == tournament.TournamentId).ToList();
            foreach (var round in tournament.Rounds)
            {
                round.Matchups = allMatchups.Where(x => x.RoundId == round.RoundId).ToList();
                foreach (var matchup in round.Matchups)
                {
                    matchup.MatchupEntries = allMatchupEntries.Where(x => x.MatchupId == matchup.MatchupId).ToList();
                    foreach (var team in matchup.MatchupEntries)
                    {
                        team.TheTeam = tournament.TournamentEntries.Where(x => x.TournamentEntryId == team.TournamentEntryId).First();
                    }
                }
            }

            return(tournament);
        }
        public IMatchup saveTeamScore(IMatchup matchup)
        {
            List <ITeam> allTeams   = TeamsTable.GetAll(dbConn);
            ITeam        firstTeam  = allTeams.Find(x => x.TeamId == matchup.MatchupEntries[0].TheTeam.TeamId);
            ITeam        secondTeam = allTeams.Find(x => x.TeamId == matchup.MatchupEntries[1].TheTeam.TeamId);

            if (matchup.MatchupEntries[0].Score > matchup.MatchupEntries[1].Score)
            {
                firstTeam.Wins++;
                secondTeam.Losses++;
            }
            else
            {
                firstTeam.Losses++;
                secondTeam.Wins++;
            }

            ITeam team1 = TeamsTable.Update(firstTeam, dbConn);
            ITeam team2 = TeamsTable.Update(secondTeam, dbConn);

            return(matchup);
        }
        public List <ITeam> getTeamsFromTournamentId(int tournamentId)
        {
            var results           = new List <ITeam>();
            var tournamentEntries = TournamentEntryTable.GetAll(dbConn);
            var teams             = TeamsTable.GetAll(dbConn);
            var teamHashTable     = teams.ToDictionary(x => x.TeamId, x => x);

            for (int i = 0; i < tournamentEntries.Count; i++)
            {
                if (tournamentEntries[i].TournamentId == tournamentId)
                {
                    do
                    {
                        results.Add(teamHashTable[tournamentEntries[i].TeamId]);
                        i++;
                    }while (i < tournamentEntries.Count && tournamentEntries[i].TournamentId == tournamentId);
                    break;
                }
            }

            return(results);
        }