Tournament Dashboard fixed, started to wire up tournamentviewer form
This commit is contained in:
@ -13,5 +13,6 @@ namespace TrackerLibrary.DataAccess
|
||||
void CreateTournament(TournamentModel model);
|
||||
List<TeamModel> GetTeam_All();
|
||||
List<PersonModel> GetPerson_All();
|
||||
List<TournamentModel> GetTournament_All();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,5 +124,12 @@ namespace TrackerLibrary.DataAccess
|
||||
tournaments.SaveToTournamentFile(TournamentFile);
|
||||
}
|
||||
|
||||
public List<TournamentModel> GetTournament_All()
|
||||
{
|
||||
return TournamentFile
|
||||
.FullFilePath()
|
||||
.LoadFile()
|
||||
.ConvertToTournamentModels(TeamFile, PeopleFile, PrizesFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,6 +108,8 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
List<TournamentModel> output = new List<TournamentModel>();
|
||||
List<TeamModel> teams = teamFileName.FullFilePath().LoadFile().ConvertToTeamModels(peopleFileName);
|
||||
List<PrizeModel> prizes = prizesFileName.FullFilePath().LoadFile().ConvertToPrizeModels();
|
||||
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] cols = line.Split(',');
|
||||
@ -120,13 +122,27 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
tm.EnteredTeams.Add(teams.Where(x => x.Id == int.Parse(teamId)).First());
|
||||
}
|
||||
string[] prizeIds = cols[4].Split('|');
|
||||
foreach (string prizeId in prizeIds)
|
||||
if (cols[4].Length > 0)
|
||||
{
|
||||
tm.Prizes.Add(prizes.Where(x => x.Id == int.Parse(prizeId)).First());
|
||||
string[] prizeIds = cols[4].Split('|');
|
||||
foreach (string prizeId in prizeIds)
|
||||
{
|
||||
tm.Prizes.Add(prizes.Where(x => x.Id == int.Parse(prizeId)).First());
|
||||
}
|
||||
}
|
||||
|
||||
// Capture rounds information
|
||||
string[] rounds = cols[5].Split('|');
|
||||
foreach (string round in rounds)
|
||||
{
|
||||
List<MatchupModel> ms = new List<MatchupModel>();
|
||||
string[] mstext = round.Split('^');
|
||||
foreach (string matchupModelTextId in mstext)
|
||||
{
|
||||
ms.Add(matchups.Where(x => x.Id == int.Parse(matchupModelTextId)).First());
|
||||
}
|
||||
tm.Rounds.Add(ms);
|
||||
}
|
||||
|
||||
output.Add(tm);
|
||||
|
||||
@ -197,7 +213,14 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
string[] cols = line.Split(',');
|
||||
MatchupEntryModel me = new MatchupEntryModel();
|
||||
me.Id = int.Parse(cols[0]);
|
||||
me.TeamCompeting = LookupTeamById(int.Parse( cols[1]));
|
||||
if(cols[1].Length == 0)
|
||||
{
|
||||
me.TeamCompeting = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
me.TeamCompeting = LookupTeamById(int.Parse(cols[1]));
|
||||
}
|
||||
me.Score = double.Parse( cols[2]);
|
||||
|
||||
int parentId = 0;
|
||||
@ -207,7 +230,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
}
|
||||
else
|
||||
{
|
||||
me.ParentMatchup = null);
|
||||
me.ParentMatchup = null;
|
||||
}
|
||||
|
||||
output.Add(me);
|
||||
@ -219,25 +242,54 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
string[] ids = input.Split('|');
|
||||
List<MatchupEntryModel> output = new List<MatchupEntryModel>();
|
||||
List<MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels();
|
||||
|
||||
List<string> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile();
|
||||
List<string> matchingEntries = new List<string>();
|
||||
foreach (string id in ids)
|
||||
{
|
||||
output.Add(entries.Where(x => x.Id == int.Parse(id)).First());
|
||||
foreach (string entry in entries)
|
||||
{
|
||||
string[] cols = entry.Split(',');
|
||||
if (cols[0] == id) {
|
||||
matchingEntries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output = matchingEntries.ConvertToMatchupEntryModels();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static TeamModel LookupTeamById(int id)
|
||||
{
|
||||
List<TeamModel> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(GlobalConfig.PeopleFile);
|
||||
return teams.Where(x => x.Id == id).First();
|
||||
List<string> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile();
|
||||
foreach (string team in teams)
|
||||
{
|
||||
string[] cols = team.Split(',');
|
||||
if (cols[0] == id.ToString())
|
||||
{
|
||||
List<string> matchingTeams = new List<string>();
|
||||
matchingTeams.Add(team);
|
||||
return matchingTeams.ConvertToTeamModels(GlobalConfig.PeopleFile).First();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static MatchupModel LookupMatchupById(int id)
|
||||
{
|
||||
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
|
||||
return matchups.Where(x => x.Id == id).First();
|
||||
List<string> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile();
|
||||
foreach (string matchup in matchups)
|
||||
{
|
||||
string[] cols = matchup.Split(',');
|
||||
if (cols[0] == id.ToString())
|
||||
{
|
||||
List<string> matchingMatchups = new List<string>();
|
||||
matchingMatchups.Add(matchup);
|
||||
return matchingMatchups.ConvertToMatchupModels().First();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<MatchupModel> ConvertToMatchupModels(this List<string> lines)
|
||||
@ -251,7 +303,14 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
MatchupModel p = new MatchupModel();
|
||||
p.Id = int.Parse(cols[0]);
|
||||
p.Entries = ConvertStringToMatchupEntryModels(cols[1]);
|
||||
p.Winner = LookupTeamById(int.Parse(cols[2]));
|
||||
if (cols[2].Length == 0)
|
||||
{
|
||||
p.Winner = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Winner = LookupTeamById(int.Parse(cols[2]));
|
||||
}
|
||||
p.MatchupRound = int.Parse(cols[3]);
|
||||
output.Add(p);
|
||||
}
|
||||
@ -268,6 +327,9 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
currentId = matchups.OrderByDescending(x => x.Id).First().Id + 1;
|
||||
}
|
||||
matchup.Id = currentId;
|
||||
|
||||
matchups.Add(matchup);
|
||||
|
||||
foreach (MatchupEntryModel entry in matchup.Entries)
|
||||
{
|
||||
entry.SaveEntryToFile(matchupEntryFile);
|
||||
@ -304,9 +366,14 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
string parent = "";
|
||||
if(e.ParentMatchup != null)
|
||||
{
|
||||
parent = e.ParentMatchup.Id.ToString(); ;
|
||||
parent = e.ParentMatchup.Id.ToString();
|
||||
}
|
||||
lines.Add($"{e.Id},{e.TeamCompeting.Id},{e.Score},{parent}");
|
||||
string teamCompeting = "";
|
||||
if(e.TeamCompeting != null)
|
||||
{
|
||||
teamCompeting = e.TeamCompeting.Id.ToString();
|
||||
}
|
||||
lines.Add($"{e.Id},{teamCompeting},{e.Score},{parent}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(GlobalConfig.MatchupEntryFile.FullFilePath(), lines);
|
||||
@ -319,12 +386,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
List<string> lines = new List<string>();
|
||||
foreach (TournamentModel tm in models)
|
||||
{
|
||||
lines.Add($@"{tm.Id},
|
||||
{tm.TournamentName},
|
||||
{tm.EntryFee},
|
||||
{ConvertTeamListToString(tm.EnteredTeams)},
|
||||
{ConvertPrizeListToString(tm.Prizes)},
|
||||
{ConvertRoundListToString(tm.Rounds)}");
|
||||
lines.Add($@"{tm.Id},{tm.TournamentName},{tm.EntryFee},{ConvertTeamListToString(tm.EnteredTeams)},{ConvertPrizeListToString(tm.Prizes)},{ConvertRoundListToString(tm.Rounds)}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
|
||||
Reference in New Issue
Block a user