public ITournament deleteTournament(int id) { var tournament = getTournament(id); foreach (var round in tournament.Rounds) { foreach (var matchup in round.Matchups) { foreach (var matchupEntry in matchup.MatchupEntries) { MatchupEntriesTable.Delete(matchupEntry, dbConn); } MatchupsTable.Delete(matchup, dbConn); } RoundsTable.Delete(round, dbConn); } foreach (var tournamentEntry in tournament.TournamentEntries) { TournamentEntryTable.Delete(tournamentEntry, dbConn); } foreach (var tournamentPrize in tournament.TournamentPrizes) { TournamentPrizesTable.Delete(tournamentPrize, dbConn); } TournamentTable.Delete(tournament, dbConn); return(tournament); }
public IMatchup saveMatchupScore(IMatchup matchup) { MatchupsTable.Update(matchup, dbConn); foreach (var entity in matchup.MatchupEntries) { MatchupEntriesTable.Update(entity, dbConn); } return(matchup); }
private void CreateRoundLinks(IRound round, List <ITournamentEntry> tournamentEntries) { round.Matchups.ForEach(x => x.RoundId = round.RoundId); foreach (var matchup in round.Matchups) { matchup.MatchupId = MatchupsTable.Create(matchup, dbConn).MatchupId; matchup.MatchupEntries.ForEach(x => x.MatchupId = matchup.MatchupId); foreach (var matchupEntry in matchup.MatchupEntries) { matchupEntry.TournamentEntryId = tournamentEntries.Find(x => x.TeamId == matchupEntry.TheTeam.TeamId).TournamentEntryId; matchupEntry.MatchupEntryId = MatchupEntriesTable.Create(matchupEntry, dbConn).MatchupEntryId; } } }
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); }