internal MatchViewModel GetMatchViewModel(Model.Models.Tournament tournament, Model.Models.Match match, MatchViewModel successor) { MatchViewModel matchViewModel; if (!_matches.TryGetValue(match.Id.Value, out matchViewModel)) { matchViewModel = new MatchViewModel(tournament, match, successor); _matches.Add(match.Id.Value, matchViewModel); } return(matchViewModel); }
public MatchViewModel(Model.Models.Tournament tournament, Model.Models.Match match, MatchViewModel successor) : base(match) { if (tournament == null) { throw new NullReferenceException(); } _tournament = tournament; Successor = successor; // Register message type to get informed about changes in predeseccors MessengerInstance.Register <MatchFinishedMessage>(this, m => { if (m.TournamentId == tournament.Id && m.Match == FirstPredecessor || m.Match == SecondPredecessor) { //Update current match, since one of the previous matches is finished now Model = App.RestClient.GetMatchWithHttpMessagesAsync(Model.Id.Value, _tournament.Id.Value).Result.Body; UpdateValuesFromModel(); } }); // Init values from model object UpdateValuesFromModel(); }
private void MatchesRecursion(ObservableCollection <MatchViewModel> result, MatchViewModel match) { result.Add(match); match.Predecessors.ForEach(p => MatchesRecursion(result, p)); }