public void save() { _c.getDaybyNr(_dayNr).matchScores.matchResults.Clear(); foreach (matchScoreForDisplay ctPS in matchScoresForDisplay) { MatchScore ctMS = new MatchScore(); ctMS.WinnerteamName = ctPS.WinnerTeam; ctMS.nrHolesLeft = ctPS.nrHolesLeft; ctMS.nrPoints = ctPS.nrPoints; _c.getDaybyNr(_dayNr).matchScores.matchResults.Add(ctPS.matchName, ctMS); } File.WriteAllText(_file, JsonConvert.SerializeObject(_c.getDaybyNr(_dayNr).matchScores)); }
public void addC(Compet ctC) { foreach (day ctDay in ctC.days) { foreach (flight ctFlight in ctDay.flights.Values) { foreach (match match in ctFlight.matchs.Values) { if (ctDay.matchScores.matchResults.ContainsKey(match.name)) { MatchScore ctMS = ctDay.matchScores.matchResults[match.name]; foreach (team ctT in match.teams) { #region store MatchInfo at Player level foreach (Player cttp in ctT.players.Values) { MatchInfo ctMInfo = new MatchInfo { year = ctC.year, matchScore = ctMS.CloneJson(), flight = ctFlight.CloneJson(), dayNr = ctDay.nr, matchName = match.name }; ctMInfo.myTeam = match.GetMyTeam(cttp.name).CloneJson(); ctMInfo.opTeam = match.GetOpponnentTeam(cttp.name).CloneJson(); if (!histMatchsForPlayer.ContainsKey(cttp.name)) { histMatchsForPlayer.Add(cttp.name, new MatchHistory { name = cttp.name }); } MatchHistory ctMHist = histMatchsForPlayer[cttp.name]; ctMHist.matchs.Add(ctMInfo); if (!histMatchsBeteNoire.ContainsKey(cttp.name)) { histMatchsBeteNoire.Add(cttp.name, new Dictionary <string, MatchHistory>()); } Dictionary <string, MatchHistory> ctMHistBN = histMatchsBeteNoire[cttp.name]; foreach (string ctOpP in ctMInfo.opTeam.players.Keys) { if (!ctMHistBN.ContainsKey(ctOpP)) { ctMHistBN.Add(ctOpP, new MatchHistory { name = ctOpP }); } MatchHistory ctMHistBNp = ctMHistBN[ctOpP]; ctMHistBNp.matchs.Add(ctMInfo.CloneJson()); } } #endregion #region store MatchInfo at Team level (2 players playing together) if (match.GetNbOfPlayers() == 4) { string key = getPairsKey(ctT); if (!histMatchsAsTeam.ContainsKey(key)) { histMatchsAsTeam.Add(key, new MatchHistory { name = key }); } MatchHistory ctMHist = histMatchsAsTeam[key]; MatchInfo ctMInfo = new MatchInfo { year = ctC.year, matchScore = ctMS.CloneJson(), flight = ctFlight.CloneJson(), dayNr = ctDay.nr, matchName = match.name }; ctMInfo.myTeam = match.GetMyTeam(ctT.GetPlayer1()).CloneJson(); ctMInfo.opTeam = match.GetOpponnentTeam(ctT.GetPlayer1()).CloneJson(); ctMHist.matchs.Add(ctMInfo); } #endregion } } else { throw new Exception(String.Format("Could not find matchScore for this match on day {0}: {1}", ctDay.displayName, match.name)); } } } } }