Tournament Dashboard fixed, started to wire up tournamentviewer form

This commit is contained in:
2020-04-12 21:17:01 +02:00
parent dee234408d
commit 8d3e6fdfa4
11 changed files with 294 additions and 29 deletions

View File

@ -100,7 +100,7 @@ namespace TrackerLibrary.DataAccess
SaveTournamentEntries(model, connection);
SaveTournamentRounds(model, connection);
}
}
}
private void SaveTournament(TournamentModel model, IDbConnection connection)
@ -157,7 +157,7 @@ namespace TrackerLibrary.DataAccess
p = new DynamicParameters();
p.Add("@MatchupId", matchup.Id);
if(entry.ParentMatchup == null)
if (entry.ParentMatchup == null)
{
p.Add("@ParentMatchupId", null);
}
@ -185,7 +185,7 @@ namespace TrackerLibrary.DataAccess
}
private static void SaveTournamentPrizes(TournamentModel model, IDbConnection connection)
private static void SaveTournamentPrizes(TournamentModel model, IDbConnection connection)
{
foreach (PrizeModel pz in model.Prizes)
{
@ -226,5 +226,75 @@ namespace TrackerLibrary.DataAccess
}
return output;
}
public List<TournamentModel> GetTournament_All()
{
List<TournamentModel> output;
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
{
output = connection.Query<TournamentModel>("dbo.spTournaments_GetAll").ToList();
var p = new DynamicParameters();
foreach (TournamentModel t in output)
{
// Populate prizes
p.Add("@TournamentId", t.Id);
t.Prizes = connection.Query<PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
// Populate Teams
t.EnteredTeams = connection.Query<TeamModel>("dbo.spTeam_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
foreach (TeamModel team in t.EnteredTeams)
{
p = new DynamicParameters();
p.Add("@TeamId", team.Id);
team.TeamMembers = connection.Query<PersonModel>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
}
// Populate Rounds
p = new DynamicParameters();
p.Add("@TournamentId", t.Id);
List<MatchupModel> matchups = connection.Query<MatchupModel>("dbo.spMatchups_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
foreach (MatchupModel m in matchups)
{
p = new DynamicParameters();
p.Add("@MatchupId", m.Id);
m.Entries = connection.Query<MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();
List<TeamModel> allTeams = GetTeam_All();
if (m.WinnerId > 0)
{
m.Winner = allTeams.Where(x => x.Id == m.WinnerId).First();
}
foreach (var me in m.Entries)
{
if (me.TeamCompetingId > 0)
{
me.TeamCompeting = allTeams.Where(x => x.Id == me.TeamCompetingId).First();
}
if (me.ParentMatchupId > 0)
{
me.ParentMatchup = matchups.Where(x => x.Id == me.ParentMatchupId).First();
}
}
}
// List<List<MatchupModel>>
List<MatchupModel> currRow = new List<MatchupModel>();
int currRound = 1;
foreach (MatchupModel m in matchups)
{
if(m.MatchupRound > currRound)
{
t.Rounds.Add(currRow);
currRow = new List<MatchupModel>();
currRound += 1;
}
currRow.Add(m);
}
t.Rounds.Add(currRow);
}
}
return output;
}
}
}