public void TestContractor()
        {
            var numbers = new int[] { };
            var output  = NumberListContractor.Contract(numbers);

            Assert.AreEqual("", output);

            numbers = new int[] { 1 };
            output  = NumberListContractor.Contract(numbers);
            Assert.AreEqual("1", output);

            numbers = new int[] { 1, 4, 5 };
            output  = NumberListContractor.Contract(numbers);
            Assert.AreEqual("1, 4-5", output);

            numbers = new int[] { 1, 4, 9 };
            output  = NumberListContractor.Contract(numbers);
            Assert.AreEqual("1, 4, 9", output);

            numbers = new int[] { 1, 2, 3 };
            output  = NumberListContractor.Contract(numbers);
            Assert.AreEqual("1-3", output);

            numbers = new int[] { 1, 2, 3, 6, 9, 10, 11 };
            output  = NumberListContractor.Contract(numbers);
            Assert.AreEqual("1-3, 6, 9-11", output);
        }
        public void PopulateContestant()
        {
            if (ContestantId == null)
            {
                return;                       // happens on Contestants.Clear()
            }
            var id = int.Parse(ContestantId);

            if (id == 0)
            {
                FirstName      = "";
                LastName       = "";
                Initials       = "";
                IsMale         = true;
                Nationality    = "";
                DayPhone       = "";
                EvePhone       = "";
                Fax            = "";
                WantsNoNews    = false;
                DateOfBirth    = null;
                IsConcessional = false;
                Address1       = "";
                Address2       = "";
                Email          = "";
                City           = "";
                County         = "";
                Postcode       = "";
                Country        = "";
                BCFCode        = "";
                FIDECode       = "";
                Notes          = "";
                UpdatedAt      = DateTime.Now;
                CompetedIn     = "";
            }
            else
            {
                var context = DataEntitiesProvider.Provide();
                var dbCon   = context.Contestants.FirstOrDefault(x => x.Mind_Sport_ID == id);
                Title          = dbCon.Title;
                FirstName      = dbCon.Firstname;
                LastName       = dbCon.Lastname;
                Initials       = dbCon.Initials;
                IsMale         = dbCon.Male;
                Nationality    = dbCon.Nationality;
                DayPhone       = dbCon.DayPhone;
                EvePhone       = dbCon.EvePhone;
                Fax            = dbCon.Fax;
                WantsNoNews    = dbCon.No_News.HasValue ? dbCon.No_News.Value : true;
                DateOfBirth    = dbCon.DateofBirth;
                IsConcessional = dbCon.Concessional.HasValue ? dbCon.Concessional.Value : true;
                Address1       = dbCon.Address1;
                Address2       = dbCon.Address2;
                Email          = dbCon.email;
                City           = dbCon.City;
                County         = dbCon.County;
                Postcode       = dbCon.PostCode;
                Country        = dbCon.Country;
                BCFCode        = dbCon.BCFCode;
                FIDECode       = dbCon.FIDECode;
                Notes          = dbCon.Notes;

                var years = context.Entrants
                            // Shouldn't be necessary but dipping into historic data is error-prone
                            .Where(e => e.Mind_Sport_ID == id && e.Event != null && e.Event.Olympiad_Info != null)
                            .Select(e => e.Event.Olympiad_Info.YearOf.Value)
                            .Distinct()
                            .OrderBy(y => y);
                CompetedIn = NumberListContractor.Contract(years);
            }

            IsDirty = false;
            PopulateEvents();
            PopulatePayments();
            OnPropertyChanged("Totals");
        }