private Coach SelectAvailableCoach(int nbSeat)
        {
            var availableCoach = Coaches.FirstOrDefault(c =>
                                                        c.HasSeatAvailable(nbSeat)) ?? Coaches.FirstOrDefault(c => !c.TotallyFull(nbSeat)
                                                                                                              );

            if (availableCoach == null)
            {
                throw new ApplicationException("No coach has the enough seat ");
            }
            return(availableCoach);
        }
Esempio n. 2
0
        public async void OnNavigatedTo(NavigationContext navigationContext)
        {
            this.IsEnabled = GlobalCommands.BlockWindowButtons();
            this.Coaches.AddRange(await this.leagueService.GetCoachList());
            this.Stadiums.AddRange(await this.leagueService.GetStadiumsList());
            int?teamId = (int?)navigationContext.Parameters["id"];

            if (!teamId.HasValue)
            {
                this.OKCommand = new DelegateCommand(async() =>
                {
                    this.IsEnabled = GlobalCommands.BlockWindowButtons();
                    await this.leagueService.AddTeam(this.Team);
                    regionManager.RequestNavigate(UiRegions.MainRegion, nameof(MainMenu));
                });
            }
            else
            {
                this.OKCommand = new DelegateCommand(async() =>
                {
                    this.IsEnabled      = GlobalCommands.BlockWindowButtons();
                    this.Team.CoachId   = this.SelectedCoach.Id;
                    this.Team.StadiumId = this.SelectedStadium.Id;
                    await this.leagueService.SaveChangesAsync();
                    //regionManager.RequestNavigate(UiRegions.MainRegion, nameof(MainMenu));
                    GlobalCommands.GoBackCommand.Execute(null);
                });
                this.Team = await this.leagueService.GetTeam(teamId.Value);

                this.SelectedCoach   = Coaches.FirstOrDefault(c => c.Id == Team.CoachId);
                this.SelectedStadium = Stadiums.FirstOrDefault(s => s.Id == Team.StadiumId);
                if (this.Team.Footballers != null)
                {
                    this.Footballers.AddRange(Team.Footballers);
                }
                if (this.Team.Table != null)
                {
                    this.Tables.AddRange(Team.Table);
                }
            }
            this.IsEnabled = GlobalCommands.UnlockWindowButtons();
        }