public 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(OrganizationUnit.AppendCode(parentCode, OrganizationUnit.CreateCode(1)));
            }

            return(OrganizationUnit.CalculateNextCode(lastChild.Code));
        }
        public virtual async Task MoveAsync(Guid id, Guid?parentId)
        {
            var organizationUnit = await _organizationUnitRepository.GetAsync(id);

            if (organizationUnit.ParentId == parentId)
            {
                return;
            }

            var children = await FindChildrenAsync(id, true);

            var oldCode = organizationUnit.Code;

            organizationUnit.Code = await GetNextChildCodeAsync(parentId);

            organizationUnit.ParentId = parentId;

            await ValidateOrganizationUnitAsync(organizationUnit);

            foreach (var child in children)
            {
                child.Code = OrganizationUnit.AppendCode(organizationUnit.Code, OrganizationUnit.GetRelativeCode(child.Code, oldCode));
            }
        }