private async Task UpdatePositionAsync(OrganizationUnit organizationUnit, List <OrganizationUnit> children, Guid?beforeOrganizationUnitId)
        {
            await RepairPosition(children);

            int newPosition = 1;

            if (beforeOrganizationUnitId.HasValue)
            {
                var beforeOrganizationUnit = children.Single(ou => ou.Id == beforeOrganizationUnitId.Value);
                newPosition = beforeOrganizationUnit.GetProperty <int>(OrganizationUnitExtraPropertyNames.PositionName) + 1;
            }

            foreach (var ou in children)
            {
                if (ou.GetProperty <int>(OrganizationUnitExtraPropertyNames.PositionName) >= newPosition &&
                    ou.Id != organizationUnit.Id
                    )
                {
                    ou.SetProperty(OrganizationUnitExtraPropertyNames.PositionName,
                                   ou.GetProperty <int>(OrganizationUnitExtraPropertyNames.PositionName) + 1);
                    await OrganizationUnitManager.UpdateAsync(ou);
                }
            }

            organizationUnit.SetProperty(OrganizationUnitExtraPropertyNames.PositionName, newPosition);
            await OrganizationUnitManager.UpdateAsync(organizationUnit);
        }
        public async Task <OrganizationUnitDto> UpdateOrganizationUnit(OrganizationUnitOutput input)
        {
            var organizationUnits = input.OrganizationUnit;
            var organizationUnit  = await _organizationRepository.GetAsync(organizationUnits.Id);

            var parent = _organizationRepository.GetAll().Where(o => o.Id == organizationUnits.ParentId).FirstOrDefault();

            if (parent != null)
            {
                var temp = parent.Number + "," + parent.Id.ToString();
                organizationUnit.Number = temp;
            }
            else
            {
                organizationUnit.Number = "0";
            }
            organizationUnit.DisplayName = organizationUnits.DisplayName;
            organizationUnit.Leader      = organizationUnits.Leader;
            organizationUnit.IsShop      = organizationUnits.IsShop;
            organizationUnit.Status      = organizationUnits.Status;
            await _organizationUnitManager.UpdateAsync(organizationUnit);



            return(await CreateOrganizationUnitDto(organizationUnit));
        }
        public virtual async Task <OrganizationUnitDto> UpdateAsync(Guid id, OrganizationUnitUpdateDto input)
        {
            var ou = await OrganizationUnitRepository.GetAsync(id, true);

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

            ou.DisplayName      = input.DisplayName;
            ou.ConcurrencyStamp = input.ConcurrencyStamp;
            ou.SetProperty(OrganizationUnitExtraPropertyNames.IsActiveName, input.IsActive);

            foreach (var roleId in ou.Roles.Select(our => our.RoleId).Except(input.RoleIds))
            {
                ou.RemoveRole(roleId);
            }
            foreach (var roleId in input.RoleIds.Except(ou.Roles.Select(our => our.RoleId)))
            {
                ou.AddRole(roleId);
            }

            await OrganizationUnitManager.UpdateAsync(ou);

            //remove cache
            await CacheOrganizationUnits.RemoveAsync(AllOrganizationUnitsListCacheName);

            return(ObjectMapper.Map <OrganizationUnit, OrganizationUnitDto>(ou));
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public async Task UpdateOrganizationUnit(OrganizationUnitDto input)
        {
            var ou = await _ouRepository.GetAsync(input.Id);

            input.MapTo(ou);
            await _organizationUnitManager.UpdateAsync(ou);
        }
Esempio n. 5
0
        protected virtual async Task Update(CreateOrEditDeliverableDto input)
        {
            var deliverable = await _deliverableRepository.FirstOrDefaultAsync((int)input.Id);

            var mapped = ObjectMapper.Map(input, deliverable);
            await _organizationUnitManager.UpdateAsync(mapped);

            await CurrentUnitOfWork.SaveChangesAsync();
        }
Esempio n. 6
0
        protected virtual async Task Update(CreateOrEditMdaDto input)
        {
            var mda = await _mdaRepository.FirstOrDefaultAsync((int)input.Id);

            mda.DisplayName         = input.DisplayName;
            mda.ResponsiblePersonId = input.ResponsiblePersonId;
            mda.Role = input.Role;

            await _organizationUnitManager.UpdateAsync(mda);
        }
        public async Task <OrganizationUnitDto> UpdateOrganizationUnit(UpdateOrganizationUnitInput input)
        {
            var organizationUnit = await _organizationUnitRepository.GetAsync(input.Id);

            organizationUnit.DisplayName = input.DisplayName;

            await _organizationUnitManager.UpdateAsync(organizationUnit);

            return(await CreateOrganizationUnitDto(organizationUnit));
        }
Esempio n. 8
0
        public override async Task <OrganizationUnitDto> Update(UpdateOrganizationUnitDto input)
        {
            CheckUpdatePermission();
            var organizationUnit = await Repository.GetAsync(input.Id);

            organizationUnit.DisplayName = input.DisplayName;

            await _organizationUnitManager.UpdateAsync(organizationUnit);

            return(await CreateOrganizationUnitDto(organizationUnit));
        }
Esempio n. 9
0
    public async Task UpdateAsync()
    {
        var ou = await _organizationUnitRepository.GetAsync("OU111");

        ou.DisplayName = "OU111 Updated";
        await _organizationUnitManager.UpdateAsync(ou);

        var ouAfterChange = await _organizationUnitRepository.GetAsync("OU111 Updated");

        ouAfterChange.DisplayName.ShouldContain("OU111 Updated");
    }
        public virtual async Task RemoveRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input)
        {
            var origanizationUnit = await OrganizationUnitRepository.GetAsync(input.Id);

            if (origanizationUnit.IsInRole(input.RoleId))
            {
                origanizationUnit.RemoveRole(input.RoleId);
                await OrganizationUnitManager.UpdateAsync(origanizationUnit);

                await CurrentUnitOfWork.SaveChangesAsync();
            }
        }
        public virtual async Task <OrganizationUnitOutput> UpdateOrganizationUnitAsync(UpdateOrganizationUnitInput input)
        {
            var entity = _organizationUnitRepository.Get(input.Id);

            if (entity.IsStatic())
            {
                throw new Exception("The display name of static organizations are not modifiable!");
            }
            entity.DisplayName = input.DisplayName.Trim();
            await _organizationUnitManager.UpdateAsync(entity);

            return(Map <OrganizationUnitOutput>(entity));
        }
Esempio n. 12
0
        public virtual async Task <OrganizationUnitDto> UpdateAsync(Guid id, OrganizationUnitUpdateDto input)
        {
            var origanizationUnit = await OrganizationUnitRepository.GetAsync(id);

            origanizationUnit.DisplayName = input.DisplayName;
            input.MapExtraPropertiesTo(origanizationUnit);

            await OrganizationUnitManager.UpdateAsync(origanizationUnit);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <OrganizationUnit, OrganizationUnitDto>(origanizationUnit));
        }
Esempio n. 13
0
        public async Task <UpdateOrganizationUnitInput> UpdateAsync(Guid Id, UpdateOrganizationUnitInput input)
        {
            //var entity = await OrganizationUnitRepository.GetAsync(input.DisplayName);
            var entity = await _repository.GetAsync(Id);

            entity.DisplayName = input.DisplayName;
            input.Code         = entity.Code;
            input.ParentId     = entity.ParentId;
            input.id           = entity.Id;

            await OrganizationUnitManager.UpdateAsync(entity);

            return(input);
        }
 public async Task CreateOrEditOrgUnit(OrganizationUnitInput input)
 {
     if (input.Id != 0)
     {
         var orgUnit = _organizationUnitRepository.Get(input.Id);
         var updated = input.MapTo(orgUnit);
         await _organizationUnitManager.UpdateAsync(updated);
     }
     else
     {
         await _organizationUnitManager.CreateAsync(new OrganizationUnit(AbpSession.TenantId, input.DisplayName,
                                                                         input.ParentId));
     }
 }
 private async Task RepairPosition(List <OrganizationUnit> children)
 {
     foreach (var ou in children)
     {
         if (!ou.HasProperty(OrganizationUnitExtraPropertyNames.PositionName))
         {
             var maxPosition = children.Where(c => c.HasProperty(OrganizationUnitExtraPropertyNames.PositionName))
                               .Select(c => c.GetProperty <int>(OrganizationUnitExtraPropertyNames.PositionName))
                               .DefaultIfEmpty(0).Max();
             ou.SetProperty(OrganizationUnitExtraPropertyNames.PositionName, maxPosition + 1);
             await OrganizationUnitManager.UpdateAsync(ou);
         }
     }
 }
        public async Task <OrganizationUnitListDto> Update(UpdateOrganizationUnitInput input)
        {
            var organizationUnit = await _organizationUnitRepository.GetAsync(input.Id);

            if (organizationUnit == null)
            {
                throw new UserFriendlyException("指定用户不存在");
            }

            organizationUnit.DisplayName = input.DisplayName;

            await _organizationUnitManager.UpdateAsync(organizationUnit);

            return(await CreateOrganizationUnit(organizationUnit));
        }
Esempio n. 17
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));
        }
Esempio n. 18
0
        public async Task <OrganizationUnitDto> UpdateOrganizationUnit(UpdateOrganizationUnitInput input)
        {
            var organizationUnit = await _organizationUnitRepository.GetAsync(input.Id);

            organizationUnit.ManagerId   = input.ManagerId;
            organizationUnit.DisplayName = input.DisplayName;
            organizationUnit.HasApprove  = input.HasApprove;
            organizationUnit.Locations   = _organizationLocationRepository.GetAll().Where(x => x.OrganizationUnitId == organizationUnit.Id).ToList();

            var oldOrganizationLocations = new HashSet <OrganizationLocation>(organizationUnit.Locations.ToList());
            var newOrganizationLocations = new HashSet <OrganizationLocationDto>(input.Locations.ToList());

            foreach (var detail in oldOrganizationLocations)
            {
                if (!newOrganizationLocations.Any(x => x.Id == detail.Id))
                {
                    organizationUnit.Locations.Remove(detail);
                }
                else
                {
                    var inputDetail = newOrganizationLocations.Where(x => x.Id == detail.Id).FirstOrDefault();
                }
            }

            foreach (var item in newOrganizationLocations)
            {
                if (item.Id == 0)
                {
                    organizationUnit.Locations.Add(ObjectMapper.Map <OrganizationLocation>(item));
                }
            }

            await _organizationUnitManager.UpdateAsync(organizationUnit);

            return(await CreateOrganizationUnitDto(organizationUnit));
        }
Esempio n. 19
0
 public async Task UpdateAsync(OrganizationUnit organizationUnit)
 {
     await _entityManager.UpdateAsync(organizationUnit);
 }