Ejemplo n.º 1
0
        public async Task Should_Move_OU_Under_Other_OU_With_Children()
        {
            //Arrange
            var ou1 = GetOU("OU1");
            var ou2 = GetOU("OU2");

            //Act
            await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id);

            //Assert
            ou1 = GetOU("OU1");
            ou1.ParentId.ShouldBe(ou2.Id);
            ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2));

            var ou11 = GetOU("OU11");

            ou11.ParentId.ShouldBe(ou1.Id);
            ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1));

            var ou111 = GetOU("OU111");

            ou111.ParentId.ShouldBe(ou11.Id);
            ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1));

            var ou112 = GetOU("OU112");

            ou112.ParentId.ShouldBe(ou11.Id);
            ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2));

            var ou12 = GetOU("OU12");

            ou12.ParentId.ShouldBe(ou1.Id);
            ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2));
        }
Ejemplo n.º 2
0
    public async Task MoveAsync()
    {
        var ou1 = await _organizationUnitRepository.GetAsync("OU1");

        var ou2 = await _organizationUnitRepository.GetAsync("OU2");

        await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id);

        ou1 = await _organizationUnitRepository.GetAsync("OU1");

        ou1.ParentId.ShouldBe(ou2.Id);
        ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2));

        var ou11 = await _organizationUnitRepository.GetAsync("OU11");

        ou11.ParentId.ShouldBe(ou1.Id);
        ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1));

        var ou111 = await _organizationUnitRepository.GetAsync("OU111");

        ou111.ParentId.ShouldBe(ou11.Id);
        ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1));

        var ou112 = await _organizationUnitRepository.GetAsync("OU112");

        ou112.ParentId.ShouldBe(ou11.Id);
        ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2));

        var ou12 = await _organizationUnitRepository.GetAsync("OU12");

        ou12.ParentId.ShouldBe(ou1.Id);
        ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2));
    }
        public async Task <OrganizationUnitDto> MoveOrganizationUnit(MoveOrganizationUnitInput input)
        {
            var parent           = _organizationRepository.GetAll().Where(o => o.Id == input.NewParentId).FirstOrDefault();
            var organizationUnit = await _organizationRepository.GetAsync(input.Id);

            if (parent != null)
            {
                var temp = parent.Number + "," + parent.Id.ToString();
                organizationUnit.Number = temp;
            }
            else
            {
                organizationUnit.Number = "0";
            }
            await _organizationUnitManager.MoveAsync(input.Id, input.NewParentId);


            //WeChatOrganization wechat = new WeChatOrganization
            //{
            //    name = organizationUnit.DisplayName,
            //    parentid = organizationUnit.ParentId,
            //    order = 1,
            //    id = organizationUnit.Id,
            //    value = "Mail"
            //};
            //BackgroundJob.Schedule<IQYWechatAppService>(x => x.UpdateWeChatOrganization(wechat), TimeSpan.FromMinutes(5));
            return(await CreateOrganizationUnitDto(
                       await _organizationRepository.GetAsync(input.Id)
                       ));
        }
        public virtual async Task MoveAsync(Guid id, OrganizationUnitMoveInput input)
        {
            var ou = await OrganizationUnitRepository.GetAsync(id, false);

            await AuthorizationService.CheckAsync(ou, CommonOperations.Update);

            if (input.ParentId != ou.ParentId)
            {
                if (input.ParentId.HasValue)
                {
                    var parentOrganizationUnit = await OrganizationUnitRepository.GetAsync(input.ParentId.Value, false);

                    await AuthorizationService.CheckAsync(parentOrganizationUnit, CommonOperations.Create);
                }
                else
                {
                    await AuthorizationService.CheckAsync(null, CommonOperations.Create);
                }
            }

            await OrganizationUnitManager.MoveAsync(ou.Id, input.ParentId);

            var children = await OrganizationUnitRepository.GetChildrenAsync(input.ParentId, false);

            await UpdatePositionAsync(ou, children, input.BeforeOrganizationUnitId);
        }
        public async Task <OrganizationUnitDto> MoveOrganizationUnit(MoveOrganizationUnitInput input)
        {
            await _organizationUnitManager.MoveAsync(input.Id, input.NewParentId);

            return(await CreateOrganizationUnitDto(
                       await _organizationUnitRepository.GetAsync(input.Id)
                       ));
        }
Ejemplo n.º 6
0
        public async Task <OrganizationUnitDto> MoveOrganizationUnit(MoveOrganizationUnitInput input)
        {
            var children = await GetAllChildren(input.Id);

            if (children.Contains(input.NewParentId ?? 0))
            {
                throw new UserFriendlyException("检查到嵌套层级结构,保存失败");
            }

            await _organizationUnitManager.MoveAsync(input.Id, input.NewParentId);

            return(await CreateOrganizationUnitDto(
                       await _organizationUnitRepository.GetAsync(input.Id)
                       ));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新当前租户下的特定组织
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <OrgUnitDto> UpdateAsync(OrgUnitDto input)
        {
            var orgUnit = await _orgUnitRepository
                          .GetAllIncluding(ou => ou.Children)
                          .FirstOrDefaultAsync(ou => ou.Id == input.Id);

            if (orgUnit.ParentId != input.ParentId)
            {
                await _orgUnitManager.MoveAsync(orgUnit.Id, input.ParentId);
            }

            orgUnit.DisplayName = input.DisplayName;

            await _orgUnitManager.UpdateAsync(orgUnit);

            return(ObjectMapper.Map <OrgUnitDto>(orgUnit));
        }
Ejemplo n.º 8
0
 public virtual async Task MoveAsync(Guid id, Guid?parentId)
 {
     await OrganizationUnitManager.MoveAsync(id, parentId);
 }
Ejemplo n.º 9
0
 public virtual async Task MoveAsync(Guid id, OrganizationUnitMoveDto input)
 {
     await OrganizationUnitManager.MoveAsync(id, input.ParentId);
 }
 public async Task MoveOrgUnit(MoveOrganizationUnitInput input)
 {
     await _organizationUnitManager.MoveAsync(input.Id, input.ParentId);
 }
Ejemplo n.º 11
0
 public virtual async Task MoveAsync(long id, long?parentId)
 {
     await(_entityManager.MoveAsync(id, parentId));
 }
Ejemplo n.º 12
0
 public async Task MoveAsync(OrganizationMoveInput input)
 {
     await _organizationUnitManager.MoveAsync(input.OrganizationId, input.OrganizationParentId);
 }