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

@ -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);