using Caliburn.Micro; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TrackerLibrary.Models; namespace TrackerWPFUI.ViewModels { public class TournamentViewerViewModel : Screen { public TournamentModel Tournament { get; set; } private BindableCollection _rounds = new BindableCollection(); private BindableCollection _matchups = new BindableCollection(); private bool _unplayedOnly; private string _teamOne; private string _teamTwo; private double _teamOneScore; private double _teamTwoScore; private MatchupModel _selectedMatchup; private int _selectedRound = 0; public TournamentViewerViewModel(TournamentModel model) { Tournament = model; LoadRounds(); } public int SelectedRound { get { return _selectedRound; } set { _selectedRound = value; NotifyOfPropertyChange(() => SelectedRound); LoadMatchups(); } } public MatchupModel SelectedMatchup { get { return _selectedMatchup; } set { _selectedMatchup = value; NotifyOfPropertyChange(() => SelectedMatchup); LoadMatchup(); } } public double TeamTwoScore { get { return _teamTwoScore; } set { _teamTwoScore = value; } } public double TeamOneScore { get { return _teamOneScore; } set { _teamOneScore = value; } } public string TeamTwo { get { return _teamTwo; } set { _teamTwo = value; NotifyOfPropertyChange(() => TeamTwo); } } public string TeamOne { get { return _teamOne; } set { _teamOne = value; NotifyOfPropertyChange(() => TeamOne); } } public bool UnplayedOnly { get { return _unplayedOnly; } set { _unplayedOnly = value; NotifyOfPropertyChange(() => UnplayedOnly); LoadMatchups(); } } public BindableCollection Matchups { get { return _matchups; } set { _matchups = value; } } public BindableCollection Rounds { get { return _rounds; } set { _rounds = value; } } private void LoadRounds() { Rounds.Clear(); Rounds.Add(1); int currRound = 1; foreach (List matchups in Tournament.Rounds) { if (matchups.First().MatchupRound > currRound) { currRound = matchups.First().MatchupRound; Rounds.Add(currRound); } } SelectedRound = 1; } private void LoadMatchups() { foreach (List matchups in Tournament.Rounds) { if (matchups.First().MatchupRound == SelectedRound) { //loading = true; Matchups.Clear(); foreach (MatchupModel mm in matchups) { if (mm.Winner == null || !UnplayedOnly) { Matchups.Add(mm); } } //loading = false; } } if (Matchups.Count > 0) { SelectedMatchup = Matchups.First(); } } private void LoadMatchup() { //if (!loading) //{ if (SelectedMatchup == null) { return; } for (int i = 0; i < SelectedMatchup.Entries.Count; i++) { if (i == 0) { if (SelectedMatchup.Entries[0].TeamCompeting != null) { TeamOne = SelectedMatchup.Entries[0].TeamCompeting.TeamName; TeamOneScore = SelectedMatchup.Entries[0].Score; TeamTwo = ""; TeamTwoScore = 0; } else { TeamOne = "Not Yet Set"; TeamOneScore = 0; } } if (i == 1) { if (SelectedMatchup.Entries[1].TeamCompeting != null) { TeamTwo = SelectedMatchup.Entries[1].TeamCompeting.TeamName; TeamTwoScore = SelectedMatchup.Entries[1].Score; } else { TeamTwo = "Not Yet Set"; TeamTwoScore = 0; } } } //} } } }