Beispiel #1
0
 public async Task AddRoleToOrganizationUnitAsync(OrganizationUnitRolesInput input)
 {
     if (input.RoleIds.Count > 0)
     {
         foreach (var roleid in input.RoleIds)
         {
             await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(roleid, input.OuId);
         }
     }
 }
Beispiel #2
0
    public async Task AddRoleToOrganizationUnitAsync()
    {
        OrganizationUnit ou        = null;
        IdentityRole     adminRole = null;

        using (var uow = _unitOfWorkManager.Begin())
        {
            ou = await _organizationUnitRepository.GetAsync("OU1", true);

            adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin"));

            await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole, ou);

            await _organizationUnitRepository.UpdateAsync(ou);

            await uow.CompleteAsync();
        }

        ou = await _organizationUnitRepository.GetAsync("OU1", includeDetails : true);

        ou.Roles.First().RoleId.ShouldBe(adminRole.Id);
    }
Beispiel #3
0
        public virtual async Task AddRolesAsync(Guid id, OrganizationUnitAddRoleDto input)
        {
            var origanizationUnit = await OrganizationUnitRepository.GetAsync(id);

            var roles = await RoleRepository.GetListByIdListAsync(input.RoleIds, includeDetails : true);

            foreach (var role in roles)
            {
                await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(role, origanizationUnit);
            }

            await CurrentUnitOfWork.SaveChangesAsync();
        }
        public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input)
        {
            var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id, true);

            var notInRoleOuIds = input.OrganizationUnitIds.Where(ouid => !origanizationUnits.Any(ou => ou.Id.Equals(ouid)));

            foreach (var ouId in notInRoleOuIds)
            {
                await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(id, ouId);
            }

            var removeRoleOriganzationUnits = origanizationUnits.Where(ou => !input.OrganizationUnitIds.Contains(ou.Id));

            foreach (var origanzationUnit in removeRoleOriganzationUnits)
            {
                origanzationUnit.RemoveRole(id);
            }

            await CurrentUnitOfWork.SaveChangesAsync();
        }
    public async Task AddRoleToOrganizationUnit()
    {
        using (var uow = _unitOfWorkManager.Begin())
        {
            var ou111 = await _organizationUnitRepository.GetAsync(
                _lookupNormalizer.NormalizeName("OU111"));

            ou111.Roles.Count.ShouldBe(2);
            var roleSupporter = await _identityRoleRepository.FindByNormalizedNameAsync(
                _lookupNormalizer.NormalizeName("supporter"));

            await _organizationUnitManager.AddRoleToOrganizationUnitAsync(roleSupporter.Id, ou111.Id);

            await uow.CompleteAsync();
        }

        var ou111Updated = await _organizationUnitRepository.GetAsync(
            _lookupNormalizer.NormalizeName("OU111"));

        ou111Updated.Roles.Count.ShouldBeGreaterThan(2);
    }
Beispiel #6
0
 public async Task AddRoleToOrganizationUnitAsync(Guid id, Guid roleId)
 {
     await _organizationUnitManager.AddRoleToOrganizationUnitAsync(roleId, id);
 }