Exemple #1
0
        protected override async void ExecuteAddCommand(object obj)
        {
            // Add Season to choose
            var seasons = await _adminClient.GetSeasonsAsync();

            var result = new List <SeasonCheckBox>();

            // Create SeasonCheckBox
            seasons.ToList().ForEach(x =>
            {
                result.Add(new SeasonCheckBox
                {
                    Season = x,
                    // Default is null
                    IsAdded = false
                });
            });

            var addBettorWindow = new AddTeamWindowController
            {
                Team    = new Team(),
                Seasons = result
            };

            var showTeam = addBettorWindow.ShowTeam();

            // it could be possible that the bettor is null
            if (showTeam == null)
            {
                return;
            }
            // Check if service is available
            if (!await AdminClientHelper.IsAvailable(_adminClient))
            {
                return;
            }
            // add bettor
            var isAdded = await _adminClient.AddTeamAsync(showTeam);

            var addedSeasons  = addBettorWindow.Seasons.FindAll(x => x.IsAdded);
            var allTeamsAsync = await _adminClient.GetAllTeamsAsync();

            var team = allTeamsAsync.ToList().Find(x => x.Name.ToUpper().Equals(showTeam.Name.ToUpper()));

            if (addedSeasons.Any())
            {
                addedSeasons.ToList().ForEach(x => _adminClient.AddSeasonToTeamRelation(new SeasonToTeamRelation {
                    Team = team, Season = x.Season
                }));
            }
            UpdateModels(isAdded, "Mannschaft konnte nicht hinzugefügt werden, da der Name schon vergeben ist!", "Hinzufügen fehlgeschlagen");
        }
Exemple #2
0
        public override async void Initialize(MainWindow mainWindow)
        {
            MainWindow   = mainWindow;
            _view        = new TeamWindow();
            _adminClient = new AdminClientServiceClient();

            #region View and ViewModel
            // Check if service is available
            if (!await AdminClientHelper.IsAvailable(_adminClient))
            {
                return;
            }

            var teams = await _adminClient.GetAllTeamsAsync();

            _viewModel = new TeamWindowViewModel
            {
                Teams         = teams.ToList(),
                BackCommand   = new RelayCommand(ExecuteBackCommand),
                AddCommand    = new RelayCommand(ExecuteAddCommand),
                DeleteCommand = new RelayCommand(ExecuteDeleteCommand),
                ChangeCommand = new RelayCommand(ExecuteChangeCommand)
            };

            _view.DataContext = _viewModel;
            #endregion

            MainWindow.Content = _view;
        }
Exemple #3
0
        protected override async void ExecuteChangeCommand(object obj)
        {
            if (_viewModel.SelectedMatch == null)
            {
                MessageBox.Show("Bitte wählen Sie ein Spiel aus!", "Kein Spiel ausgewählt",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            // Check if service is available
            if (!await AdminClientHelper.IsAvailable(_adminClient))
            {
                return;
            }
            var teams = await _adminClient.GetAllTeamsAsync();

            var addBettorWindow = new AddMatchWindowController
            {
                Match     = _viewModel.SelectedMatch,
                AwayTeams = teams.ToList(),
                HomeTeams = teams.ToList()
            };

            var showMatch = addBettorWindow.ShowMatch();

            // it could be possible that the bettor is null
            if (showMatch == null)
            {
                ReloadModels();
                return;
            }
            // Check if service is available
            if (!await AdminClientHelper.IsAvailable(_adminClient))
            {
                return;
            }
            // add bettor
            var isUpdated = await _adminClient.UpdateMatchAsync(showMatch);

            UpdateModels(isUpdated, "Das Spiel konnte nicht geändert werden!", "Änderung fehlgeschlagen");
        }