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." }); }
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); }
public async Task AddAsync(Node profile) { await _nodeRepository.AddAsync(profile); await _nodeRepository.SaveChangesAsync(); }