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));
            await OrganizationUnitRepository.UpdateAsync(child);
        }

        await OrganizationUnitRepository.UpdateAsync(organizationUnit);
    }
        public virtual Task AddRoleToOrganizationUnitAsync(IdentityRole role, OrganizationUnit ou)
        {
            var currentRoles = ou.Roles;

            if (currentRoles.Any(r => r.OrganizationUnitId == ou.Id && r.RoleId == role.Id))
            {
                return(Task.FromResult(0));
            }
            ou.AddRole(role.Id);
            return(OrganizationUnitRepository.UpdateAsync(ou));
        }
Exemple #3
0
        public virtual async Task UpdateAsync(OrganizationUnit organizationUnit)
        {
            await ValidateOrganizationUnitAsync(organizationUnit);

            await OrganizationUnitRepository.UpdateAsync(organizationUnit);
        }
 public virtual Task RemoveRoleFromOrganizationUnitAsync(IdentityRole role, OrganizationUnit organizationUnit)
 {
     organizationUnit.RemoveRole(role.Id);
     return(OrganizationUnitRepository.UpdateAsync(organizationUnit));
 }