Ejemplo n.º 1
0
 /// <summary>
 /// Возвращает путь для вставки в конец
 /// </summary>
 /// <param name="parentPath"></param>
 /// <returns></returns>
 public HierarchyId GetAppendPath(HierarchyId parentPath)
 {
     var index = context.Blocks.Count(x => x.Path.GetLevel() == parentPath.GetLevel() + 1
                                           && x.Path.IsDescendantOf(parentPath)) + 1;
     HierarchyId newItemPath = HierarchyId.Parse(parentPath + index.ToString() + "/");
     return newItemPath;
 }
Ejemplo n.º 2
0
        private void Dive(TreeItem currentNode, HierarchyId currentPath)
        {
            var newBlock = new Block
            {
                Id = Guid.NewGuid(),
                Path = currentPath,
                Level = currentPath.GetLevel(),
                BlockName = currentNode.Name,
                IsChoice = currentNode.IsChoice,
                Order = currentNode.Order,
                AttributeList = new Collection<AttributeMetadata>()
            };
            var subBlocks = currentNode.SubItems.Where(x => x.SubItems != null).ToArray();

            //блок
            for (int i = 1; i <= subBlocks.Length; i++)
            {
                var subItem = currentNode.SubItems[i - 1];
                Dive(subItem, HierarchyId.Parse(currentPath + i.ToString() + "/"));
            }
            /*var subAttributes = currentNode.SubItems.Where(x => x.SubItems == null).Select(x => new AttributeMetadata
                {
                    Id = Guid.NewGuid(),
                    AttributeName = x.Name,
                    BlockId = newBlock.Id,
                    Placeholder = x.Placeholder,
                });*/
            foreach (var node in currentNode.SubItems.Where(x => x.SubItems == null))
            {
                newBlock.AttributeList.Add(new AttributeMetadata
                {
                    Id = Guid.NewGuid(),
                    AttributeName = node.Name,
                    Placeholder = node.Placeholder,
                    Order = node.Order
                });
            }
            context.Blocks.Add(newBlock);
        }