Exemplo n.º 1
0
        private void LoadMatchupSelectionChanged()
        {
            MatchupModel m = (MatchupModel)Lbx_matchup.SelectedItem;

            for (int i = 0; i < m.Entries.Count; i++)
            {
                if (i == 0)
                {
                    if (m.Entries[0].TeamCompeting != null)
                    {
                        Lbl_teamOnename.Content = m.Entries[0].TeamCompeting.TeamName;
                        Tbx_teamOneScore.Text   = m.Entries[0].Score.ToString();

                        Lbl_teamTwoName.Content = "Bye";
                        Tbx_teamTwoScore.Text   = "0";
                    }
                    else
                    {
                        Lbl_teamOnename.Content = "Not yet set";
                        Tbx_teamOneScore.Text   = "";
                    }
                }

                if (i == 1)
                {
                    if (m.Entries[1].TeamCompeting != null)
                    {
                        Lbl_teamTwoName.Content = m.Entries[1].TeamCompeting.TeamName;
                        Tbx_teamTwoScore.Text   = m.Entries[1].Score.ToString();
                    }
                    else
                    {
                        Lbl_teamTwoName.Content = "Not yet set";
                        Tbx_teamTwoScore.Text   = "";
                    }
                }
            }
        }
        public static void SaveMatchupToFile(this MatchupModel matchup, string matchupFile, string matchupEntryFile)
        {
            List <MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();

            int currentId = 1;

            if (matchups.Count > 0)
            {
                currentId = matchups.OrderByDescending(x => x.Id).First().Id + 1;
            }

            matchup.Id = currentId;

            matchups.Add(matchup);


            foreach (MatchupEntryModel entry in matchup.Entries)
            {
                entry.SaveEntryToFile(matchupEntryFile);
            }

            //saving to file
            List <string> lines = new List <string>();

            //id = 0, entries =1(limited by pipe by ID), winner =2, matchupRpund = 3
            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);
        }