Exemplo n.º 1
0
        public void Delete(Entity channelEntity, int parentEntityId, Entity targetEntity, string linkTypeId, List <int> productParentIds = null)
        {
            var    channelHelper     = new ChannelHelper(_context);
            string channelIdentifier = channelHelper.GetChannelIdentifier(channelEntity);
            string folderDateTime    = DateTime.Now.ToString("yyyyMMdd-HHmmss.fff");

            channelHelper.BuildEntityIdAndTypeDict(DeleteUtilConfig);


            if (!DeleteUtilConfig.ChannelEntities.ContainsKey(targetEntity.Id))
            {
                DeleteUtilConfig.ChannelEntities.Add(targetEntity.Id, targetEntity);
            }

            string resourceZipFile = string.Format("resource_{0}.zip", folderDateTime);

            if (_context.ExtensionManager.ChannelService.EntityExistsInChannel(channelEntity.Id, targetEntity.Id))
            {
                var existingEntities = _context.ExtensionManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(
                    channelEntity.Id,
                    targetEntity.Id);

                Entity parentEnt = _context.ExtensionManager.DataService.GetEntity(parentEntityId, LoadLevel.DataOnly);

                if (parentEnt != null)
                {
                    if (!DeleteUtilConfig.ChannelEntities.ContainsKey(parentEnt.Id))
                    {
                        DeleteUtilConfig.ChannelEntities.Add(parentEnt.Id, parentEnt);
                    }
                    if (targetEntity.EntityType.Id == "Resource")
                    {
                        DeleteResource(
                            targetEntity,
                            parentEnt,
                            channelIdentifier,
                            folderDateTime,
                            resourceZipFile);
                    }
                    else
                    {
                        DeleteEntityThatStillExistInChannel(
                            channelEntity,
                            targetEntity,
                            parentEnt,
                            linkTypeId,
                            existingEntities,
                            channelIdentifier,
                            folderDateTime,
                            resourceZipFile);
                    }
                }
                else
                {
                    _context.Log(LogLevel.Information, $"Unable to find entity {parentEntityId} (already deleted?)");
                }
            }
            else
            {
                //DeleteEntity
                DeleteEntity(
                    channelEntity,
                    parentEntityId,
                    targetEntity,
                    linkTypeId,
                    channelIdentifier,
                    folderDateTime,
                    productParentIds);
            }
        }