The TournamentViewer is quite ready, just the score-handling is left to wire up
This commit is contained in:
@ -29,13 +29,23 @@ namespace TrackerWPFUI.ViewModels
|
||||
ActivateItem(new CreateTournamentViewModel());
|
||||
}
|
||||
|
||||
public void LoadTournament()
|
||||
{
|
||||
if (SelectedTournament !=null && !string.IsNullOrWhiteSpace(SelectedTournament.TournamentName))
|
||||
{
|
||||
ActivateItem(new TournamentViewerViewModel(SelectedTournament));
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(TournamentModel message)
|
||||
{
|
||||
// Open the tournamentViewer to the given tournament
|
||||
throw new NotImplementedException();
|
||||
ExistingTournaments.Add(message);
|
||||
SelectedTournament = message;
|
||||
}
|
||||
|
||||
private BindableCollection<TournamentModel> _existingTournaments;
|
||||
private TournamentModel _SelectedTournament;
|
||||
|
||||
public BindableCollection<TournamentModel> ExistingTournaments
|
||||
{
|
||||
@ -43,7 +53,6 @@ namespace TrackerWPFUI.ViewModels
|
||||
set { _existingTournaments = value; }
|
||||
}
|
||||
|
||||
private TournamentModel _SelectedTournament;
|
||||
|
||||
public TournamentModel SelectedTournament
|
||||
{
|
||||
@ -52,9 +61,8 @@ namespace TrackerWPFUI.ViewModels
|
||||
{
|
||||
_SelectedTournament = value;
|
||||
NotifyOfPropertyChange(() => SelectedTournament);
|
||||
LoadTournament();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
206
TrackerWPFUI/ViewModels/TournamentViewerViewModel.cs
Normal file
206
TrackerWPFUI/ViewModels/TournamentViewerViewModel.cs
Normal file
@ -0,0 +1,206 @@
|
||||
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<int> _rounds = new BindableCollection<int>();
|
||||
private BindableCollection<MatchupModel> _matchups = new BindableCollection<MatchupModel>();
|
||||
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<MatchupModel> Matchups
|
||||
{
|
||||
get { return _matchups; }
|
||||
set { _matchups = value; }
|
||||
}
|
||||
|
||||
|
||||
public BindableCollection<int> Rounds
|
||||
{
|
||||
get { return _rounds; }
|
||||
set { _rounds = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void LoadRounds()
|
||||
{
|
||||
Rounds.Clear();
|
||||
|
||||
Rounds.Add(1);
|
||||
int currRound = 1;
|
||||
foreach (List<MatchupModel> matchups in Tournament.Rounds)
|
||||
{
|
||||
if (matchups.First().MatchupRound > currRound)
|
||||
{
|
||||
currRound = matchups.First().MatchupRound;
|
||||
Rounds.Add(currRound);
|
||||
}
|
||||
}
|
||||
|
||||
SelectedRound = 1;
|
||||
}
|
||||
|
||||
private void LoadMatchups()
|
||||
{
|
||||
foreach (List<MatchupModel> 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 = "<bye>";
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user