Beispiel #1
0
        private List <FailureModel> GetFailureModels(IEnumerable <Failure> failures)
        {
            // Index sales areas by name
            var salesAreasByName = SalesArea.IndexListByName(_salesAreaRepository.GetAll());

            // Map Failure to FailureModel
            var failuresModels = _mapper.Map <List <FailureModel> >(failures);

            failuresModels.ForEach(fm => fm.SalesAreaShortName = salesAreasByName.ContainsKey(fm.SalesAreaName) ? salesAreasByName[fm.SalesAreaName].ShortName : fm.SalesAreaShortName);
            return(failuresModels);
        }
Beispiel #2
0
        private static AgSpotsSerialization ToAgSpot(
            List <Spot> spots,
            List <SalesArea> salesAreas,
            IReadOnlyCollection <BreakWithProgramme> breaks,
            List <Campaign> campaigns,
            List <Demographic> demographics,
            List <BusinessType> businessTypes,
            List <Product> products,
            List <Clash> clashes,
            AgSpot agSpot,
            IFeatureManager featureManager)
        {
            var agSpots = new ConcurrentBag <AgSpot>();

            Dictionary <string, SalesArea> salesAreasByName               = SalesArea.IndexListByName(salesAreas);
            Dictionary <string, Campaign>  campaignsByExternalId          = Campaign.IndexListByExternalId(campaigns);
            Dictionary <string, bool>      businessTypesInclusionSettings = businessTypes
                                                                            .ToDictionary(bt => bt.Code, bt => bt.IncludeConversionIndex);
            Dictionary <string, BreakWithProgramme> breaksWithProgrammeBySalesAreaAndExternalBreakRef = BreakWithProgramme.IndexListBySalesAreaAndExternalBreakRef(breaks);
            IImmutableDictionary <string, Product>  productByExternalId = products.IndexListByExternalID();
            IImmutableDictionary <string, Clash>    clashByExternalRef  = clashes.IndexListByExternalRef();

            var clashRoots = ClashHelper.CalculateClashTopParents(clashByExternalRef);

            var threadSafeSpotsCollection = spots.ToImmutableList();
            var includeNominalPrice       = featureManager.IsEnabled(nameof(ProductFeature.NominalPrice));
            var includePositionInBreak    = featureManager.IsEnabled(nameof(ProductFeature.PositionInBreak));

            _ = Parallel.ForEach(threadSafeSpotsCollection, spot => agSpots.Add(
                                     GetAgSpot(
                                         spot,
                                         threadSafeSpotsCollection,
                                         salesAreasByName,
                                         campaignsByExternalId,
                                         businessTypesInclusionSettings,
                                         breaksWithProgrammeBySalesAreaAndExternalBreakRef,
                                         productByExternalId,
                                         clashByExternalRef,
                                         demographics,
                                         agSpot.Clone(),
                                         includeNominalPrice,
                                         includePositionInBreak,
                                         clashRoots
                                         )
                                     )
                                 );

            var serialization = new AgSpotsSerialization();

            return(serialization.MapFrom(agSpots.ToList()));
        }