Exemplo n.º 1
0
        protected virtual async Task <string> GetNextChildCodeAsync(Guid?parentId)
        {
            var lastChild = await GetLastChildOrNullAsync(parentId);

            if (lastChild == null)
            {
                var parentCode = parentId != null ? await GetCodeAsync(parentId.Value) : null;

                return(TreeCodeGenerator.AppendCode(parentCode, TreeCodeGenerator.CreateCode(1)));
            }

            return(TreeCodeGenerator.CalculateNextCode(lastChild.Code));
        }
Exemplo n.º 2
0
        private async Task traverseTreeAsync(TEntity parent, ICollection <TEntity> children, bool autoSave = false, CancellationToken cancellationToken = default)
        {
            if (children == null || !children.Any())
            {
                return;
            }
            var index = 0;

            foreach (var c in children)
            {
                var code = TreeCodeGenerator.AppendCode(parent.Code, TreeCodeGenerator.CreateCode(++index));
                c.SetCode(code);
                TraverseTreeAction?.Invoke(c);
                await traverseTreeAsync(c, c.Children, autoSave, cancellationToken);
            }
        }