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"); }
public override async void Initialize(MainWindow mainWindow) { _adminClient = new AdminClientServiceClient(); MainWindow = mainWindow; #region View And ViewModel _view = new MatchesWindow(); // Check if service is available if (!await AdminClientHelper.IsAvailable(_adminClient)) { return; } var seasons = await _adminClient.GetSeasonsAsync(); var matches = await _adminClient.GetMatchesAsync(seasons.FirstOrDefault()); _viewModel = new MatchesWindowViewModel { Seasons = seasons.ToList(), SelectedSeason = seasons.FirstOrDefault(), Matches = matches.ToList(), BackCommand = new RelayCommand(ExecuteBackCommand), AddCommand = new RelayCommand(ExecuteAddCommand), DeleteCommand = new RelayCommand(ExecuteDeleteCommand), ChangeCommand = new RelayCommand(ExecuteChangeCommand), GenerateMatchesCommand = new RelayCommand(ExecuteGenerateCommand), LoadMatchDayCommand = new RelayCommand(ExecuteLoadMatchCommand) }; _view.DataContext = _viewModel; _viewModel.SelectionSeasonChanged += UpdateSeason; #endregion _view.MatchesDataGrid.Loaded += SetMinWidths; MainWindow.Content = _view; }
public override async void Initialize(MainWindow mainWindow) { MainWindow = mainWindow; _adminClient = new AdminClientServiceClient(); #region View And ViewModel // Check if service is available if (!await AdminClientHelper.IsAvailable(_adminClient)) { return; } _view = new SeasonWindow(); var seasons = await _adminClient.GetSeasonsAsync(); _viewModel = new SeasonWindowViewModel { BackCommand = new RelayCommand(ExecuteBackCommand), AddCommand = new RelayCommand(ExecuteAddCommand), DeleteCommand = new RelayCommand(ExecuteDeleteCommand), ChangeCommand = new RelayCommand(ExecuteChangeCommand), Seasons = seasons.ToList(), }; _view.DataContext = _viewModel; #endregion MainWindow.Content = _view; }
protected override async void ReloadModels() { var seasons = await _adminClient.GetSeasonsAsync(); _viewModel.Seasons = seasons.ToList(); }