Exemple #1
0
        /// <date>14/03/15</date>
        /// <summary>
        /// Saves the current list to a file.
        /// </summary>
        public void SaveAthletes()
        {
            foreach (AthleteType athlete in AthleteCollection)
            {
                switch (athlete.Status)
                {
                case StatusType.Added:
                    if (athlete.PredeclaredHandicap.Contains(":"))
                    {
                        int initialHandicapMinutes = 0;
                        int initialHandicapSeconds = 0;

                        if (int.TryParse(athlete.PredeclaredHandicap.Substring(0, athlete.PredeclaredHandicap.IndexOf(":")), out initialHandicapMinutes))
                        {
                            if (int.TryParse(athlete.PredeclaredHandicap.Substring(athlete.PredeclaredHandicap.IndexOf(":") + 1), out initialHandicapSeconds))
                            {
                                this.model.CreateNewAthlete(
                                    athlete.Name,
                                    athlete.Club,
                                    initialHandicapMinutes,
                                    initialHandicapSeconds,
                                    athlete.Sex,
                                    ListOCConverter.ToList(athlete.RunningNumbers),
                                    athlete.BirthYear,
                                    athlete.BirthMonth,
                                    athlete.BirthDay,
                                    athlete.SignedConsent,
                                    athlete.Active);
                            }
                        }
                    }
                    else
                    {
                        int initialHandicap = 0;
                        if (int.TryParse(athlete.PredeclaredHandicap, out initialHandicap))
                        {
                            this.model.CreateNewAthlete(
                                athlete.Name,
                                athlete.Club,
                                initialHandicap,
                                athlete.Sex,
                                ListOCConverter.ToList(athlete.RunningNumbers),
                                athlete.BirthYear,
                                athlete.BirthMonth,
                                athlete.BirthDay,
                                athlete.SignedConsent,
                                athlete.Active);
                        }
                    }

                    break;

                case StatusType.Deleted:
                    this.model.DeleteAthlete(athlete.Key);
                    break;

                case StatusType.Updated:
                    this.model.UpdateAthlete(
                        athlete.Key,
                        athlete.Club,
                        ListOCConverter.ToList(athlete.RunningNumbers),
                        athlete.SignedConsent,
                        athlete.Active,
                        new TimeType(athlete.PredeclaredHandicap));
                    break;

                default:
                    break;
                }
            }

            this.model.SaveAthleteList();
            ResetSelectedIndex();
            LoadAthleteInformation();

            Messenger.Default.Send(
                new HandicapProgressMessage(
                    "Athletes Saved"));
        }