/* Creates OU tree as shown below:
         *
         * - OU1
         *   - OU11
         *     - OU111
         *     - OU112
         *   - OU12
         * - OU2
         *   - OU21
         */
        private async Task AddOrganizationUnits()
        {
            var ou1 = await CreateOU("OU1", OrganizationUnit.CreateCode(1));

            var ou11 = await CreateOU("OU11", OrganizationUnit.CreateCode(1, 1), ou1.Id);

            _ou112 = await CreateOU("OU112", OrganizationUnit.CreateCode(1, 1, 2), ou11.Id);

            var ou12 = await CreateOU("OU12", OrganizationUnit.CreateCode(1, 2), ou1.Id);

            var ou2 = await CreateOU("OU2", OrganizationUnit.CreateCode(2));

            var ou21 = await CreateOU("OU21", OrganizationUnit.CreateCode(2, 1), ou2.Id);

            _ou111      = new OrganizationUnit(_guidGenerator.Create(), "OU111", ou11.Id);
            _ou111.Code = OrganizationUnit.CreateCode(1, 1, 1);
            _ou111.AddRole(_moderatorRole.Id);
            _ou111.AddRole(_managerRole.Id);
            await _organizationUnitRepository.InsertAsync(_ou111);
        }
Beispiel #2
0
        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(Task.FromResult(0));
        }