Ejemplo n.º 1
0
        public async Task <IList <Race> > GetRacesAsync(Season season)
        {
            try
            {
                var dto = await this.nratingsApiClient.GetRacesAsync(season.Id);

                return(dto.Select(r => new Race()
                {
                    Id = r.Id,
                    Season = season,
                    RaceName = r.RaceName,
                    RaceDate = r.RaceDate,
                    Track = new Track()
                    {
                        Id = r.TrackId, Name = r.TrackName
                    },
                    TrackLengthMiles = r.TrackLengthMiles,
                    Surface = r.Surface,
                    RaceLengthMiles = r.RaceLengthMiles,
                    Cautions = r.Cautions,
                    CautionLaps = r.CautionLaps,
                    LeadChanges = r.LeadChanges
                }).ToList());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void chkSeasons_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Checked && this.chkSeasons.CheckedItems.Count >= maxSeasons)
            {
                MessageBox.Show("You have reached the maximum of " + maxSeasons.ToString() + " selected seasons. Uncheck another season first.", "Season limit reached", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                if (!this.seasonIndicesToUncheck.Contains(e.Index))
                {
                    this.seasonIndicesToUncheck.Add(e.Index);
                }
            }
            else
            {
                Season season = this.chkSeasons.Items[e.Index] as Season;

                if (season != null)
                {
                    if (e.NewValue == CheckState.Checked)
                    {
                        IList <Race> seasonRaces = this.rdp.GetRaces(season);

                        if (seasonRaces != null)
                        {
                            foreach (Race race in seasonRaces)
                            {
                                this.bsRaces.Add(race);
                                this.dgRaces.Rows[this.bsRaces.IndexOf(race)].Cells["Select"].Value = false;
                            }
                        }
                    }
                    else
                    {
                        List <Race> racesToRemove = new List <Race>();

                        foreach (object o in bsRaces)
                        {
                            Race race = o as Race;

                            if (race != null)
                            {
                                if (race.Season.Id == season.Id)
                                {
                                    racesToRemove.Add(race);
                                }
                            }
                        }

                        foreach (Race race in racesToRemove)
                        {
                            this.bsRaces.Remove(race);
                            this.rdp.SelectRace(race, false);
                        }

                        if (this.chkSeasons.CheckedItems.Count == 0)
                        {
                            this.CleanUpRaces();
                        }
                    }


                    //SORT THE RACES BY DATE
                    List <Race> allRaces = this.bsRaces.DataSource as List <Race>;
                    if (allRaces != null)
                    {
                        allRaces.Sort();
                        this.dgRaces.Refresh();
                        this.CorrectRaceSelections();
                    }

                    //READJUST THE COLUMN WIDTHS
                    this.dgRaces.AutoResizeColumns();
                }

                if (this.bsRaces.Count > 0)
                {
                    this.EnableRaceSelectionButtons(true);
                }
                else
                {
                    this.EnableRaceSelectionButtons(false);
                }
            }
        }