Пример #1
0
        private void ImportPilot(string[] record)
        {
            if (Competitions.Count() == 0)
            {
                throw new InvalidOperationException("Pilot import is not allowed when no competitions are defined");
            }

            var number = int.Parse(record[1]);

            Pilot pilot;

            if (Pilots.Any(p => p.Number == number))
            {
                pilot = Pilots.First(p => p.Number == number);
            }
            else
            {
                if (Tasks.Count() > 0)
                {
                    throw new InvalidOperationException("Cannot add pilots when there are tasks defined");
                }

                pilot = new Pilot()
                {
                    Number = number
                };
                Pilots.Add(pilot);
            }

            pilot.Name    = record[2].Trim();
            pilot.Country = (record.Length > 3) ? record[3].Trim() : "";
            pilot.Balloon = (record.Length > 4) ? record[4].Trim() : "";
        }