Beispiel #1
0
        public virtual async Task MoveAsync(Guid id, Guid?parentId)
        {
            var organizationUnit = await OrganizationUnitRepository.GetAsync(id);

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

            //Should find children before Code change
            var children = await FindChildrenAsync(id, true);

            //Store old code of OU
            var oldCode = organizationUnit.Code;

            //Move OU
            organizationUnit.Code = await GetNextChildCodeAsync(parentId);

            organizationUnit.ParentId = parentId;

            await ValidateOrganizationUnitAsync(organizationUnit);

            //Update Children Codes
            foreach (var child in children)
            {
                child.Code = OrganizationUnit.AppendCode(organizationUnit.Code, OrganizationUnit.GetRelativeCode(child.Code, oldCode));
            }
        }
Beispiel #2
0
        public virtual async Task <string> GetNextChildCodeAsync(Guid?parentId)
        {
            var lastChild = await GetLastChildOrNullAsync(parentId);

            if (lastChild != null)
            {
                return(OrganizationUnit.CalculateNextCode(lastChild.Code));
            }

            var parentCode = parentId != null
                ? await GetCodeOrDefaultAsync(parentId.Value)
                : null;

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