/// <summary>Prepares the related data.</summary> /// <param name="campaigns">The campaigns.</param> protected override void PrepareRelatedData(IReadOnlyCollection <Campaign> campaigns) { var productExternalIds = campaigns.Select(c => c.Product).Where(s => !string.IsNullOrWhiteSpace(s)) .Distinct(StringComparer.OrdinalIgnoreCase).ToList().ToList(); _products = _productRepository.FindByExternal(productExternalIds).ToDictionary(x => x.Externalidentifier); var allClashes = _clashRepository.GetAll().IndexListByExternalRef(); _clashRoots = ClashHelper.CalculateClashTopParents(allClashes); }
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())); }