Exemplo n.º 1
0
        public OutputImmutableDataSnapshot(RunWithScenarioReference runWithScenarioRef, IRunRepository runRepository,
                                           IScenarioRepository scenarioRepository, IPassRepository passRepository,
                                           ICampaignRepository campaignRepository, IScheduleRepository scheduleRepository,
                                           ISalesAreaRepository salesAreaRepository, IDemographicRepository demographicRepository,
                                           IProgrammeDictionaryRepository programmeDictionaryRepository, ISpotRepository spotRepository,
                                           IMetadataRepository metadataRepository)
        {
            var runStartDate = new Lazy <DateTime>(() => Run.Value.StartDate.Add(Run.Value.StartTime));
            var runEndDate   = new Lazy <DateTime>(() => DateHelper.ConvertBroadcastToStandard(Run.Value.EndDate, Run.Value.EndTime));

            Run                      = new Lazy <Run>(() => runRepository.Find(runWithScenarioRef.RunId));
            Scenario                 = new Lazy <Scenario>(() => scenarioRepository.Get(runWithScenarioRef.ScenarioId), true);
            ScenarioPasses           = new Lazy <IEnumerable <Pass> >(() => passRepository.FindByScenarioId(runWithScenarioRef.ScenarioId), true);
            AllCampaigns             = new Lazy <IEnumerable <Campaign> >(campaignRepository.GetAll, true);
            AllSalesAreas            = new Lazy <IEnumerable <SalesArea> >(salesAreaRepository.GetAll, true);
            AllDemographics          = new Lazy <IEnumerable <Demographic> >(demographicRepository.GetAll, true);
            AllProgrammeDictionaries = new Lazy <IEnumerable <ProgrammeDictionary> >(programmeDictionaryRepository.GetAll, true);
            BreakTypes               = new Lazy <IEnumerable <string> >(() => metadataRepository.GetByKey(MetaDataKeys.BreakTypes).Select(e => (string)e.Value));

            SpotsForRun = new Lazy <IEnumerable <Spot> >(() =>
            {
                var salesAreaPriorities = Run.Value.SalesAreaPriorities.Count == 0
                    ? AllSalesAreas.Value
                    : AllSalesAreas.Value.Where(sa => Run.Value.SalesAreaPriorities.Find(rsa => rsa.SalesArea == sa.Name) != null);

                return(spotRepository.Search(
                           runStartDate.Value,
                           runEndDate.Value,
                           salesAreaPriorities.Select(sa => sa.Name).ToList()
                           ));
            },
                                                         true
                                                         );

            BreaksForRun = new Lazy <IEnumerable <BreakSimple> >(() =>
                                                                 scheduleRepository.GetScheduleSimpleBreaks(
                                                                     AllSalesAreas.Value.Select(c => c.Name).ToList(),
                                                                     runStartDate.Value,
                                                                     runEndDate.Value
                                                                     ),
                                                                 true
                                                                 );
        }