Exemple #1
0
        public List <XElement> GetParentXElements(Entity parentEntity, Configuration configuration)
        {
            List <XElement> elements = new List <XElement>();
            List <string>   parents  = new List <string>();

            if (parentEntity == null)
            {
                return(elements);
            }

            if (parentEntity.EntityType.Id == "Item" && configuration.ItemsToSkus)
            {
                parents = _epiElement.SkuItemIds(parentEntity, configuration);
            }
            else
            {
                parents.Add(parentEntity.Id.ToString(CultureInfo.InvariantCulture));
            }
            var channelPrefixHelper = new ChannelPrefixHelper(_context);

            foreach (var parent in parents)
            {
                XElement parentElement = new XElement("parent", channelPrefixHelper.GetEPiCodeWithChannelPrefix(parent, configuration));
                elements.Add(parentElement);
            }

            return(elements);
        }
Exemple #2
0
        public void EpiCodeFieldUpdatedAddAssociationAndRelationsToDocument(XDocument doc, Entity updatedEntity, Configuration config, int channelId)
        {
            List <Link> links = new List <Link>();
            var         channelPrefixHelper = new ChannelPrefixHelper(_context);
            var         epiMappingHelper    = new EpiMappingHelper(_context);


            if (updatedEntity.EntityType.IsLinkEntityType)
            {
                links = _context.ExtensionManager.DataService.GetLinksForLinkEntity(updatedEntity.Id);
            }
            else
            {
                links = _context.ExtensionManager.DataService.GetLinksForEntity(updatedEntity.Id);
            }

            List <XElement> associationsElements = new List <XElement>();

            Dictionary <string, XElement> relationsElements = new Dictionary <string, XElement>();

            foreach (Link link in links)
            {
                var structureEntityList = _context.ExtensionManager.ChannelService.GetAllStructureEntitiesForEntityWithParentInChannel
                                              (channelId, link.Target.Id, link.Source.Id);

                if (!epiMappingHelper.IsRelation(
                        link.LinkType.SourceEntityTypeId,
                        link.LinkType.TargetEntityTypeId,
                        link.LinkType.Index,
                        config))
                {
                    foreach (StructureEntity structureEntity in structureEntityList)
                    {
                        if (!structureEntity.LinkEntityId.HasValue)
                        {
                            associationsElements.Add(_epiElement.CreateCatalogAssociationElement(
                                                         structureEntity,
                                                         null,
                                                         config));
                        }
                        else
                        {
                            associationsElements.Add(_epiElement.CreateCatalogAssociationElement(
                                                         structureEntity,
                                                         link.LinkEntity,
                                                         config));
                        }
                    }
                }
                else
                {
                    foreach (StructureEntity structureEntity in structureEntityList)
                    {
                        int parentNodeId = GetParentChannelNode(structureEntity, channelId);

                        if (parentNodeId == 0)
                        {
                            continue;
                        }

                        string channelPrefixAndSkuId        = channelPrefixHelper.GetEPiCodeWithChannelPrefix(structureEntity.EntityId, config);
                        string channelPrefixAndParentNodeId = channelPrefixHelper.GetEPiCodeWithChannelPrefix(parentNodeId, config);

                        if (!relationsElements.ContainsKey(channelPrefixAndSkuId + "_" + channelPrefixAndParentNodeId))
                        {
                            relationsElements.Add(channelPrefixAndSkuId + "_" + channelPrefixAndParentNodeId,
                                                  _epiElement.CreateNodeEntryRelationElement(
                                                      parentNodeId.ToString(CultureInfo.InvariantCulture),
                                                      structureEntity.EntityId.ToString(),
                                                      structureEntity.SortOrder,
                                                      config));
                        }

                        string channelPrefixAndParent = channelPrefixHelper.GetEPiCodeWithChannelPrefix(structureEntity.ParentId, config);

                        if (!relationsElements.ContainsKey(channelPrefixAndSkuId + "_" + channelPrefixAndParent))
                        {
                            relationsElements.Add(channelPrefixAndSkuId + "_" + channelPrefixAndParent,
                                                  _epiElement.CreateEntryRelationElement(
                                                      structureEntity.ParentId.ToString(CultureInfo.InvariantCulture),
                                                      link.LinkType.SourceEntityTypeId,
                                                      structureEntity.EntityId.ToString(),
                                                      structureEntity.SortOrder, config));
                        }
                    }
                }
            }

            if (relationsElements.Any())
            {
                doc.Descendants("Relations").ElementAt(0).Add(new XAttribute("totalCount", relationsElements.Count), relationsElements.Values);
            }

            if (associationsElements.Any())
            {
                doc.Descendants("Associations").ElementAt(0).Add(new XAttribute("totalCount", associationsElements.Count), associationsElements);
            }
        }