Пример #1
0
        public IEnumerable <DimVal> GetTopLevelBrowseDimVals()
        {
            var result           = new List <DimVal>();
            var usedDimensionIds = new List <long>();
            var sections         =
                EndecaUtils.GetRefinements(new List <long> {
                0, EndecaSectionId
            }, null, false, true)
                .GetDimension(EndecaSectionId).Refinements;

            foreach (var sectionDimVal in sections.Cast <DimVal>())
            {
                // Replacing var dimensionValueLinks = GetDimensionValueLinks(828847, sectionDimVal, null, false);
                var sectionValue = sectionDimVal;
                var dimensionId  = TopCategoryId;

                var dims = ProcessDimVals(sectionValue, dimensionId, string.Empty, string.Empty, false, null, false);
                foreach (var dimVal in dims)
                {
                    if (!usedDimensionIds.Contains(dimVal.Id))
                    {
                        result.Add(dimVal);
                        usedDimensionIds.Add(dimVal.Id);
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public IEnumerable <DimVal> ProcessDimVals(DimVal dimFirst, long dimensionId, string idTrail, string breadcrumbTrail, bool appendBreadcrumbTrail, int?indigoParentCategoryId, bool enforceUpdate, DimVal dimSecond = null, bool isFrench = false)
        {
            var result = new List <DimVal>();

            if (string.IsNullOrWhiteSpace(breadcrumbTrail))
            {
                breadcrumbTrail = string.Empty;
            }

            if (string.IsNullOrWhiteSpace(idTrail))
            {
                idTrail = string.Empty;
            }

            DimVal dimensionValue = dimSecond;
            var    sectionValue   = dimFirst;
            var    dimValList     = dimensionValue == null
                             ? new List <DimVal> {
                sectionValue
            }
                             : new List <DimVal> {
                sectionValue, dimensionValue
            };

            var dimension =
                EndecaUtils.GetRefinements(new List <long> {
                EndecaSectionId, dimensionId
            }, dimValList, false, false)
                .GetDimension(dimensionId);

            if (dimension != null && dimension.Refinements != null && dimension.Refinements.Count > 0)
            {
                var dimensionRefinements = dimension.Refinements;
                if (dimensionRefinements.Count > 0)
                {
                    var placeHolderBreadcrumbTrail = breadcrumbTrail;
                    var placeHolderIdTrail         = idTrail;
                    foreach (var dimRef in dimensionRefinements)
                    {
                        var dimVal = (DimVal)dimRef;
                        idTrail         += IdTrailSplitter + dimVal.Id;
                        breadcrumbTrail += BreadcrumbTrailSplitter + dimVal.Name;
                        IIndigoCategory match      = null;
                        var             hasChanged = enforceUpdate;
                        if (appendBreadcrumbTrail)
                        {
                            Log.Debug(idTrail + ":" + breadcrumbTrail);
                            match = _existingIndigoCategories.FirstOrDefault(ic => ic.EndecaBreadcrumbId.Equals(idTrail, StringComparison.OrdinalIgnoreCase));
                            if (match == null)
                            {
                                var indigoCategory = GetIndigoCategory(indigoParentCategoryId, dimVal.Name, dimVal.GetFrenchName(), idTrail, (int)dimVal.Id, breadcrumbTrail, false);
                                match = _indigoCategoryService.Insert(indigoCategory);
                                _newItemCountDelta++;
                            }
                            else
                            {
                                // Check if the name has changed. If so, update this category and its entire branch as the breadcrumb values have changed
                                if (hasChanged ||
                                    !(string.Equals(dimVal.Name, match.Name, StringComparison.OrdinalIgnoreCase) &&
                                      string.Equals(dimVal.GetFrenchName(), match.NameFr, StringComparison.OrdinalIgnoreCase)))
                                {
                                    hasChanged           = true;
                                    match.Name           = dimVal.Name;
                                    match.NameFr         = dimVal.GetFrenchName();
                                    match.BreadcrumbPath = breadcrumbTrail;
                                    match.IsModified     = true;
                                    match.IsDeleted      = false;
                                    match = _indigoCategoryService.Update(match);
                                    _modifiedItemCountDelta++;
                                }
                                else if (match.IsDeleted)
                                {
                                    match.IsDeleted = false;
                                    match           = _indigoCategoryService.Update(match);
                                    _modifiedItemCountDelta++;
                                }
                                else
                                {
                                    _unmodifiedItemCountDelta++;
                                }
                                _existingIndigoCategories.Remove(match);
                            }
                        }

                        result.Add(dimVal);

                        var parentId = (appendBreadcrumbTrail) ? match.IndigoCategoryId : indigoParentCategoryId;

                        var linkInfoListNew = ProcessDimVals(sectionValue, dimensionId, idTrail, breadcrumbTrail, appendBreadcrumbTrail, parentId, hasChanged, dimVal, isFrench).ToList();
                        if (linkInfoListNew.Any())
                        {
                            result.AddRange(linkInfoListNew);
                        }
                        breadcrumbTrail = placeHolderBreadcrumbTrail;
                        idTrail         = placeHolderIdTrail;
                    }
                }
            }

            return(result);
        }