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 LeagueRoundModule() { Get[SharedRoutes.SeasonAllRounds] = parameters => { var seasonId = (int)parameters.seasonId; var rounds = leagueRepo.GetCurrentSeasonRounds(seasonId).Select(Mapper.Map<RoundDto>).ToList(); return Response.AsJson(rounds); }; Get[SharedRoutes.RoundGames] = parameters => { var seasonId = (int)parameters.seasonId; var roundId = (int)parameters.roundId; var gameRoundsDb = leagueRepo.GetAllRoundGames(roundId); if (gameRoundsDb.Any(g => g.SeasonRound.LeagueSeasonId != seasonId)) return HttpStatusCode.Conflict; var games = gameRoundsDb.Select(Mapper.Map<GameDto>).ToList(); return Response.AsJson(games); }; Get[SharedRoutes.CurrentRoundGames] = parameters => { var seasonId = (int)parameters.seasonId; var season = leagueRepo.GetLeagueSeasonById(seasonId); var currentRound = leagueRepo.GetCurrentSeasonRound(season); var gameRoundsDb = leagueRepo.GetAllRoundGames(currentRound.RoundId); if (gameRoundsDb.Any(g => g.SeasonRound.LeagueSeasonId != seasonId)) return HttpStatusCode.Conflict; var games = gameRoundsDb.Select(Mapper.Map<GameDto>).ToList(); return Response.AsJson(games); }; Get[SharedRoutes.SeasonRoundsTable] = parameters => { var seasonId = (int)parameters.seasonId; var rounds = leagueRepo.GetCurrentSeasonRounds(seasonId).Select(Mapper.Map<RoundStatsDto>).OrderBy(r => r.RoundNumber).ToList(); var roundTable = new RoundsTable { LeagueSeasonId = seasonId, IsFinished = rounds.Count >= 38, Rounds = rounds, StartDate = rounds.FirstOrDefault()?.StartDate, EndDate = rounds.LastOrDefault()?.EndDate, }; return Response.AsJson(roundTable); }; Get[SharedRoutes.SeasonRoundsStats] = parameters => { var seasonId = (int)parameters.seasonId; var averageRoundStats = Mapper.Map<SeasonAverageRoundDto>(analysisRepo.GetAverageRoundStats(seasonId)); return Response.AsJson(averageRoundStats); }; }
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 ITournament createTournament(ITournament entry) { ITournament tournament = TournamentTable.Create(entry, dbConn); if (tournament == null) { return(null); } entry.TournamentEntries.ForEach(x => x.TournamentId = tournament.TournamentId); entry.TournamentEntries.ForEach(x => TournamentEntryTable.Create(x, dbConn)); entry.TournamentPrizes.ForEach(x => x.TournamentId = tournament.TournamentId); entry.TournamentPrizes.ForEach(x => TournamentPrizesTable.Create(x, dbConn)); entry.Rounds.ForEach(x => x.TournamentId = tournament.TournamentId); foreach (var round in entry.Rounds) { round.RoundId = RoundsTable.Create(round, dbConn).RoundId; CreateRoundLinks(round, entry.TournamentEntries); } return(tournament); }