Esempio n. 1
0
        private void Initializate()
        {
            var matchesJson = File.ReadAllText("Matches.json");
            var matches     = JsonConvert.DeserializeObject <List <Match> >(matchesJson,
                                                                            new StringEnumConverter());
            //var s = JsonConvert.SerializeObject(matches, Formatting.Indented, new StringEnumConverter());
            //var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            //var p = Path.Combine(appData, "ScoreKeeper");
            //Directory.CreateDirectory(p);
            //var f = Path.Combine(p, "matches.json");
            //File.WriteAllText(f, s);
            var matchViewModels = new ObservableCollection <MatchViewModel>(matches.Select(m => new MatchViewModel(m)));

            AllPlayers = new ObservableCollection <string>(matches.SelectMany(m => m.StartingEleven));

            MatchesViewModel = new MatchesViewModel(matchViewModels,
                                                    new RelayCommand(_ => EditMatch(null)),
                                                    new RelayCommand(m => EditMatch(((MatchViewModel)m).Match),
                                                                     o => o != null),
                                                    dialogService);

            StatsViewModel = new StatsViewModel(matchViewModels);

            SettingsViewModel = new SettingsViewModel(() => IsSettingsFlyoutOpen = false);
        }
        private void Initializate()
        {
            var matchesJson = File.ReadAllText("Matches.json");
            var matches     = JsonConvert.DeserializeObject <List <Match> >(matchesJson,
                                                                            new StringEnumConverter());

            //var s = JsonConvert.SerializeObject(matches, Formatting.Indented, new StringEnumConverter());
            //var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            //var p = Path.Combine(appData, "ScoreKeeper");
            //Directory.CreateDirectory(p);
            //var f = Path.Combine(p, "matches.json");
            //File.WriteAllText(f, s);
            matchesView = new MatchesView();
            var matchViewModels = new ObservableCollection <MatchViewModel>(matches.Select(m => new MatchViewModel(m)));

            matchesView.DataContext = new MatchesViewModel(matchViewModels,
                                                           new RelayCommand(_ => EditMatch(null)),
                                                           new RelayCommand(m => EditMatch(((MatchViewModel)m).Match),
                                                                            o => o != null));

            statsView = new StatsView();
            var statsViewModel = new StatsViewModel(matchViewModels);

            statsView.DataContext = statsViewModel;

            navigateToView(matchesView);
        }