示例#1
0
文件: Service.cs 项目: minuss01/Tree
        public async Task <NodeViewModel> AddNodeAsync(NodeAddFormViewModel request)
        {
            Node node = new Node
            {
                Name         = request.Name,
                NodeParentId = request.NodeParentId
            };

            try
            {
                await _nodeRepository.AddAsync(node);

                await _nodeRepository.SaveChangesAsync();
            }
            catch (System.Exception ex)
            {
                return(new NodeViewModel {
                    IsSuccess = false, Message = "The node has not been added."
                });
            }

            return(new NodeViewModel {
                IsSuccess = true, Message = "The node has been added."
            });
        }
示例#2
0
        public async Task <string> AddAsync(Core.Entities.Content.Node node)
        {
            node.Id          = Guid.NewGuid().ToString();
            node.CreatedDate = DateTimeOffset.UtcNow.ToString("s");
            if (node.CustomFields != null)
            {
                node.CustomFields.Id     = Guid.NewGuid().ToString();
                node.CustomFields.NodeId = node.Id;
            }
            await _nodeRepository.AddAsync(node);

            var path = node.ParentId;

            if (!string.IsNullOrEmpty(node.ParentId))
            {
                var parent = await GetAsync(node.ParentId);

                parent.ChildCount++;
                await _nodeRepository.UpdateAsync(parent);

                if (!string.IsNullOrEmpty(parent.Path))
                {
                    path = $"{parent.Path},{node.ParentId}";
                }
            }
            node.Path = path;
            if (!string.IsNullOrEmpty(node.Path))
            {
                var nodes = await GetAncestors(node);

                foreach (var ancestorNode in nodes)
                {
                    ancestorNode.DescendantCount++;
                    await _nodeRepository.UpdateAsync(ancestorNode);
                }
            }

            await _nodeRepository.SaveChangesAsync();

            return(node.Id);
        }
示例#3
0
        public async Task AddAsync(Node profile)
        {
            await _nodeRepository.AddAsync(profile);

            await _nodeRepository.SaveChangesAsync();
        }