示例#1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                CurrentDocument = new TournamentViewModel(CreateDesignTimeVm());
                OpenedDocuments.Add(CurrentDocument);
            }
            else
            {
                new List <Model.Models.Tournament>(App.RestClient.GetAllWithHttpMessagesAsync().Result.Body).ForEach(t => Tournaments.Add(new TournamentViewModel(t)));
            }

            MessengerInstance.Register <OpenTournamentMessage>(this, m =>
            {
                OpenedDocuments.Add(m.Tournament);
                CurrentDocument = m.Tournament;
            });
            MessengerInstance.Register <CloseTournamentMessage>(this, m =>
            {
                if (OpenedDocuments.Contains(m.Sender))
                {
                    CurrentDocument = OpenedDocuments[0];
                    OpenedDocuments.Remove(m.Sender);
                }
            });
        }
示例#2
0
        internal TournamentViewModel GetTournamentViewModel(Model.Models.Tournament tournament)
        {
            if (tournament == null)
            {
                return(null);
            }
            TournamentViewModel tournamentViewModel;

            if (!_tournament.TryGetValue(tournament.Id.Value, out tournamentViewModel))
            {
                tournamentViewModel = new TournamentViewModel(tournament);
                _tournament.Add(tournament.Id.Value, tournamentViewModel);
            }
            return(tournamentViewModel);
        }