public static List <MatchupEntry> ConvertToMatchupEntry(this List <string> lines) { List <MatchupEntry> output = new List <MatchupEntry>(); foreach (string line in lines) { if (line != "") { //Id,CompetingTeamId,Score,ParentId string[] cols = line.Split(','); MatchupEntry p = new MatchupEntry(); p.Id = int.Parse(cols[0]); p.Id = int.Parse(cols[0]); p.CompetingTeamId = int.Parse(cols[1]); p.Score = int.Parse(cols[2]); p.ParentId = int.Parse(cols[3]); if (p.CompetingTeamId != 0) { p.TeamCompeting = TeamsFile.FullFilePath().LoadFile().GetOneTeam(p.CompetingTeamId); } if (p.ParentId != 0) { p.ParentMatchup = MatchupsFile.FullFilePath().LoadFile().GetOneMatchup(p.ParentId); } output.Add(p); } } return(output); }
public static MatchupEntry GetOneMatchupEntry(this List <string> lines, int memberId) { MatchupEntry output = new MatchupEntry(); foreach (string line in lines) { if (line != "") { string[] cols = line.Split(','); if (int.Parse(cols[0]) == memberId) { //Id,CompetingTeamId,Score,ParentId MatchupEntry p = new MatchupEntry(); p.Id = int.Parse(cols[0]); p.CompetingTeamId = int.Parse(cols[1]); p.Score = int.Parse(cols[2]); p.ParentId = int.Parse(cols[3]); if (p.CompetingTeamId != 0) { p.TeamCompeting = TeamsFile.FullFilePath().LoadFile().GetOneTeam(p.CompetingTeamId); } if (p.ParentId != 0) { p.ParentMatchup = MatchupsFile.FullFilePath().LoadFile().GetOneMatchup(p.ParentId); } output = p; } } } return(output); }
private static List <MatchupEntry> convertToMatchupEntries(this List <string> matchupLines) { List <MatchupEntry> entries = new List <MatchupEntry>(); foreach (string line in matchupLines) { string[] columns = line.Split('^'); MatchupEntry entry = new MatchupEntry(); entry.id = int.Parse(columns[0]); entry.TeamCompeting = findByTeamId(int.Parse(columns[1])); entry.Score = double.Parse(columns[2]); int parentid = 0; if (int.TryParse(columns[3], out parentid)) { entry.ParentMatchup = findMatchupById(int.Parse(columns[3])); } else { entry.ParentMatchup = null; } entries.Add(entry); } return(entries); }
public static void SaveMatchupEntryToFile(this MatchupEntry entry) { List <MatchupEntry> matchupEntries = GlobalConfig.MatchupEntriesFile.FullFilePath().LoadFile().ConvertToMatchupEntries(); int currentId = 1; if (matchupEntries.Count > 0) { currentId = matchupEntries.OrderByDescending(m => m.Id).First().Id + 1; } entry.Id = currentId; matchupEntries.Add(entry); List <string> lines = new List <string>(); foreach (MatchupEntry m in matchupEntries) { string parent = ""; if (m.ParentMatchup != null) { parent = m.ParentMatchup.Id.ToString(); } string teamCompeting = ""; if (m.TeamCompeting != null) { teamCompeting = m.TeamCompeting.Id.ToString(); } lines.Add($"{ m.Id },{ teamCompeting },{ m.Score },{ parent }"); } File.WriteAllLines(GlobalConfig.MatchupEntriesFile.FullFilePath(), lines); }
public static void SaveEntryToFile(this MatchupEntry entry, string matchupEntryFile) { List <MatchupEntry> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().CovertToMatchupEntryModels(); int currentId = 1; if (entries.Count > 0) { currentId = entries.OrderByDescending(x => x.Id).First().Id + 1; } entry.Id = currentId; entries.Add(entry); List <string> lines = new List <string>(); foreach (MatchupEntry 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 List <MatchupEntry> ConvertToMatchupEntrys(this List <string> lines) { List <MatchupEntry> output = new List <MatchupEntry>(); foreach (string line in lines) { string[] cols = line.Split(','); MatchupEntry me = new MatchupEntry(); me.Id = int.Parse(cols[0]); if (cols[1].Length == 0) { me.TeamCompeting = null; } else { me.TeamCompeting = LookupTeamById(int.Parse(cols[1])); } me.Score = double.Parse(cols[2]); if (int.TryParse(cols[3], out int parentId)) { me.ParentMatchup = LookupMatchupById(parentId); } else { me.ParentMatchup = null; } output.Add(me); } return(output); }
public static void UpdateEntryToFile(this MatchupEntry entry) { List <MatchupEntry> entries = GlobalConfig.MatchupEntryFile .FullFilePath() .LoadFile() .ConvertToMatchupEntrys(); MatchupEntry oldEntry = new MatchupEntry(); foreach (MatchupEntry e in entries) { if (e.Id == entry.Id) { oldEntry = e; } } entries.Remove(oldEntry); entries.Add(entry); // save to entries file List <string> lines = new List <string>(); foreach (MatchupEntry 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 UpdateMatchupEntryToFile(this MatchupEntry entry) { List <MatchupEntry> matchupEntries = GlobalConfig.MatchupEntriesFile.FullFilePath().LoadFile().ConvertToMatchupEntries(); foreach (MatchupEntry me in matchupEntries) { if (me.Id == entry.Id) { matchupEntries.Remove(me); break; } } matchupEntries.Add(entry); matchupEntries = matchupEntries.OrderBy(e => e.Id).ToList(); List <string> lines = new List <string>(); foreach (MatchupEntry m in matchupEntries) { string parent = ""; if (m.ParentMatchup != null) { parent = m.ParentMatchup.Id.ToString(); } string teamCompeting = ""; if (m.TeamCompeting != null) { teamCompeting = m.TeamCompeting.Id.ToString(); } lines.Add($"{ m.Id },{ teamCompeting },{ m.Score },{ parent }"); } File.WriteAllLines(GlobalConfig.MatchupEntriesFile.FullFilePath(), lines); }
/// <summary> /// This method alerts member about there new matchup. /// </summary> /// <param name="tournamentName">Name of ongoing tournament.</param> /// <param name="member">Member to be notified.</param> /// <param name="teamName">Name of member's team.</param> /// <param name="competitor">Competitor of the member.</param> private static void alertMemberToNewRound(string tournamentName, Person member, string teamName, MatchupEntry competitor) { //If member has no email if (member.Email.Length == 0) { return; } string to = ""; string subject = ""; StringBuilder body = new StringBuilder(); if (competitor != null && competitor.TeamCompeting != null) { subject = $"New Upcoming match with {competitor.TeamCompeting.TeamName}"; body.AppendLine("<h1>You have a new Match!!</h1>"); body.Append("<br><strong>Tournament: </strong>"); body.Append(tournamentName); body.Append("<br><strong>Competitor: </strong>"); body.Append(competitor.TeamCompeting.TeamName); body.AppendLine("<br><br>Good Luck with your match!!"); body.AppendLine("<br><br>Regards, <br>GCU Tournament Tracker"); } else { subject = "No match this week."; body.AppendLine("<h1>You have no match!!</h1>"); body.Append("<br><strong>Tournament: </strong>"); body.Append(tournamentName); body.AppendLine("<br><br>Enjoy!!"); body.AppendLine("<br><br>Regards, <br>GCU Tournament Tracker"); } to = member.Email; //Send the email Email.sendEmail(to, subject, body.ToString()); }
/// <summary> /// Saves the MatchupEntry info in file. /// </summary> /// <param name="entry">Entry whose info is to be saved.</param> /// <param name="matchupEntryFile">File where info is to be saved.</param> public static void SaveMatchupEntry(this MatchupEntry entry) { }