Every form is wired up and the system works in some meaning

This commit is contained in:
2020-04-13 23:27:51 +02:00
parent ac1fa4cfaa
commit 8758ec170d
5 changed files with 120 additions and 4 deletions

View File

@ -349,6 +349,42 @@ namespace TrackerLibrary.DataAccess.TextHelpers
File.WriteAllLines(GlobalConfig.MatchupFile.FullFilePath(), lines);
}
public static void UpdateMatchupToFile(this MatchupModel matchup)
{
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
MatchupModel oldMatchup = new MatchupModel();
foreach (MatchupModel m in matchups)
{
if(m.Id == matchup.Id)
{
oldMatchup = m;
}
}
matchups.Remove(oldMatchup);
matchups.Add(matchup);
foreach (MatchupEntryModel entry in matchup.Entries)
{
entry.UpdateEntryToFile();
}
List<string> lines = new List<string>();
foreach (MatchupModel m in matchups)
{
string winner = "";
if (m.Winner != null)
{
winner = m.Winner.Id.ToString(); ;
}
lines.Add($"{m.Id},{ConvertMatchupEntryListToString(m.Entries)},{winner},{m.MatchupRound}");
}
File.WriteAllLines(GlobalConfig.MatchupFile.FullFilePath(), lines);
}
public static void SaveEntryToFile(this MatchupEntryModel entry, string matchupEntryFile)
{
List<MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels();
@ -380,6 +416,42 @@ namespace TrackerLibrary.DataAccess.TextHelpers
}
public static void UpdateEntryToFile(this MatchupEntryModel entry)
{
List<MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels();
MatchupEntryModel oldEntry = new MatchupEntryModel();
foreach (MatchupEntryModel me in entries)
{
if(me.Id == entry.Id)
{
oldEntry = me;
}
}
entries.Remove(oldEntry);
entries.Add(entry);
List<string> lines = new List<string>();
foreach (MatchupEntryModel e in entries)
{
string parent = "";
if (e.ParentMatchup != null)
{
parent = e.ParentMatchup.Id.ToString();
}
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);
}
public static void SaveToTournamentFile(this List<TournamentModel> models, string fileName)
{