Esempio n. 1
0
        /// <inheritdoc />
        public void Seasons(ICaller caller)
        {
            using IDealData data = InstanceFactory.GetInstance <IDealData>();

            IList <ISeason> existingSeasons = data.ReadAllSeasons();

            IList <IOrganiser> existingOrganisers = data.ReadAllOrganisers();

            IList <ISeason> seasons = new List <ISeason>
            {
                new Season(
                    id: Guid.NewGuid(),
                    organiser: existingOrganisers.Single(o => o.Code == "BRADGATE"),
                    description: "2019/20",
                    startDate: new DateTime(2019, 11, 01),
                    endDate: new DateTime(2020, 10, 31)),
                new Season(
                    id: Guid.NewGuid(),
                    organiser: existingOrganisers.Single(o => o.Code == "GLENFIELD"),
                    description: "2019/20",
                    startDate: new DateTime(2019, 05, 23),
                    endDate: new DateTime(2020, 05, 20)),
                new Season(
                    id: Guid.NewGuid(),
                    organiser: existingOrganisers.Single(o => o.Code == "CBC"),
                    description: "2019/20",
                    startDate: new DateTime(2019, 06, 01),
                    endDate: new DateTime(2020, 05, 31)),
                new Season(
                    id: Guid.NewGuid(),
                    organiser: existingOrganisers.Single(o => o.Code == "CBT"),
                    description: "2019/20",
                    startDate: new DateTime(2019, 06, 01),
                    endDate: new DateTime(2020, 05, 31)),
                new Season(
                    id: Guid.NewGuid(),
                    organiser: existingOrganisers.Single(o => o.Code == "LCBA"),
                    description: "2019/20",
                    startDate: new DateTime(2019, 06, 01),
                    endDate: new DateTime(2020, 05, 31))
            };

            foreach (ISeason season in seasons)
            {
                ISeason existingSeason = existingSeasons
                                         .Where(es => es.Organiser.Code == season.Organiser.Code)
                                         .SingleOrDefault(es => es.Description == season.Description);

                if (existingSeason == null)
                {
                    data.CreateSeason(season);
                    Console.WriteLine($@"Seeding Season: {season.Organiser.Code} {season.Description}.");
                }
                else
                {
                    if (existingSeason.StartDate == season.StartDate &&
                        existingSeason.EndDate == season.EndDate)
                    {
                        continue;
                    }

                    existingSeason.SetDates(season.StartDate, season.EndDate);
                    data.UpdateSeason(existingSeason);

                    Console.WriteLine($@"Updating Season: {season.Organiser.Code} {season.Description}.");
                }
            }
        }