private void AddNormalAssociations(StructureEntity structureEntity)
        {
            var entityCode = _catalogCodeGenerator.GetEpiserverCode(structureEntity.EntityId);
            var parentCode = _catalogCodeGenerator.GetEpiserverCode(structureEntity.ParentId);

            var associationName = _epiMappingHelper.GetAssociationName(structureEntity);

            var associationKey = _catalogCodeGenerator.GetAssociationKey(entityCode, parentCode, associationName);

            if (_epiElementContainer.HasAssociation(associationKey))
            {
                return;
            }

            XElement existingAssociation = GetExistingAssociation(associationName, parentCode);

            if (existingAssociation != null)
            {
                XElement newElement = _catalogElementFactory.CreateAssociationElement(structureEntity);

                if (!existingAssociation.Descendants().Any(e => e.Name.LocalName == "EntryCode" && e.Value == entityCode))
                {
                    existingAssociation.Add(newElement);
                    _epiElementContainer.AddAssociationKey(associationKey);
                }
            }
            else
            {
                var associationElement = _catalogElementFactory.CreateCatalogAssociationElement(structureEntity);
                _epiElementContainer.AddAssociation(associationElement, associationKey);
            }
        }
예제 #2
0
        private void AddItemToSkusAssociations(LinkType linkType,
                                               StructureEntity structureEntity,
                                               string skuId)
        {
            string associationName = _epiMappingHelper.GetAssociationName(structureEntity);

            Entity source = _entityService.GetEntity(structureEntity.ParentId, LoadLevel.DataOnly);

            List <string> skuCodes = _catalogElementFactory.SkuItemIds(source);

            for (var i = 0; i < skuCodes.Count; i++)
            {
                skuCodes[i] = _catalogCodeGenerator.GetPrefixedCode(skuCodes[i]);
            }

            foreach (string skuCode in skuCodes)
            {
                string associationKey = _catalogCodeGenerator.GetAssociationKey(skuCode, structureEntity.ParentId.ToString(), associationName);
                if (_epiElementContainer.HasAssociation(associationKey))
                {
                    continue;
                }

                XElement existingCatalogAssociationElement = _epiElementContainer.Associations.FirstOrDefault(
                    x => x.Element("Name")?.Value == associationName &&
                    x.Element("EntryCode")?.Value == skuCode);
                ;

                var associationElement = new XElement("Association",
                                                      new XElement("EntryCode", skuId),
                                                      new XElement("SortOrder", structureEntity.SortOrder),
                                                      new XElement("Type", linkType.Id));

                if (existingCatalogAssociationElement != null)
                {
                    if (existingCatalogAssociationElement.Descendants().Any(e => e.Name.LocalName == "EntryCode" && e.Value == skuId))
                    {
                        continue;
                    }

                    existingCatalogAssociationElement.Add(associationElement);
                    _epiElementContainer.AddAssociationKey(associationKey);
                }
                else
                {
                    var catalogAssociation = new XElement("CatalogAssociation",
                                                          new XElement("Name", associationName),
                                                          new XElement("Description", linkType.Id),
                                                          new XElement("SortOrder", structureEntity.SortOrder),
                                                          new XElement("EntryCode", skuCode),
                                                          associationElement);

                    _epiElementContainer.AddAssociation(catalogAssociation, associationKey);
                }
            }
        }