Exemple #1
0
        public async Task <OrganizationDto> Create(CreateOrUpdateOrganizationDto input)
        {
            var exist = await _repository.FirstOrDefaultAsync(_ => _.Name == input.Name);

            if (exist != null)
            {
                throw new BusinessException("名称:" + input.Name + "机构已存在");
            }

            var organization = new Organization(GuidGenerator.Create(),
                                                CurrentTenant.Id,
                                                input.CategoryId,
                                                input.Pid,
                                                input.Name,
                                                "",
                                                input.Sort,
                                                true,
                                                input.Enabled
                                                );
            var parent = await _repository.FirstOrDefaultAsync(_ => _.Id == input.Pid);

            ChangeOrganizationModel(organization, parent);
            await _repository.InsertAsync(organization);

            return(ObjectMapper.Map <Organization, OrganizationDto>(organization));
        }
        public async Task <OrganizationDto> Update(Guid id, CreateOrUpdateOrganizationDto input)
        {
            var org = await _repository.FirstOrDefaultAsync(_ => _.Id == id);

            org.Pid  = input.Pid;
            org.Name = input.Name;

            return(ObjectMapper.Map <Organization, OrganizationDto>(org));
        }
Exemple #3
0
        public async Task <OrganizationDto> Update(Guid id, CreateOrUpdateOrganizationDto input)
        {
            var org = await _repository.FirstOrDefaultAsync(_ => _.Id == id);

            org.Pid = input.Pid;
            //TODO:后台任务执行子集fullName修改
            org.Name    = input.Name;
            org.Sort    = input.Sort;
            org.Enabled = input.Enabled;

            return(ObjectMapper.Map <Organization, OrganizationDto>(org));
        }
        public async Task <OrganizationDto> Create(CreateOrUpdateOrganizationDto input)
        {
            var exist = await _repository.FirstOrDefaultAsync(_ => _.Name == input.Name);

            if (exist != null)
            {
                throw new BusinessException("名称:" + input.Name + "字典已存在");
            }

            var result = await _repository.InsertAsync(new Organization(
                                                           GuidGenerator.Create(),
                                                           input.CategoryId,
                                                           input.Pid,
                                                           input.Name,
                                                           "",      //TODO:自动生成fullName
                                                           input.Sort,
                                                           input.Enabled,
                                                           false    //TODO:自动判断是否存在子集
                                                           ));

            return(ObjectMapper.Map <Organization, OrganizationDto>(result));
        }
Exemple #5
0
        public async Task <OrganizationDto> Create(CreateOrUpdateOrganizationDto input)
        {
            var exist = await _repository.FirstOrDefaultAsync(_ => _.Name == input.Name);

            var parent = await _repository.FirstOrDefaultAsync(_ => _.Id == input.Pid);

            if (exist != null)
            {
                throw new BusinessException("名称:" + input.Name + "机构已存在");
            }

            var result = await _repository.InsertAsync(new Organization(
                                                           GuidGenerator.Create(),
                                                           input.CategoryId,
                                                           input.Pid,
                                                           input.Name,
                                                           parent == null ? input.Name : parent.FullName + "/" + input.Name,
                                                           input.Sort,
                                                           input.Enabled
                                                           ));

            return(ObjectMapper.Map <Organization, OrganizationDto>(result));
        }
Exemple #6
0
        public async Task <OrganizationDto> Update(Guid id, CreateOrUpdateOrganizationDto input)
        {
            if (input.Pid == id)
            {
                throw new BusinessException("机构上级不能为当前机构!");
            }
            var organization = await _repository.FirstOrDefaultAsync(_ => _.Id == id);

            if (organization.Pid != input.Pid)
            {
                var parent = await _repository.FirstOrDefaultAsync(_ => _.Id == input.Pid);

                var orgs = await _repository.Where(_ => _.CascadeId.Contains(organization.CascadeId) && _.Id != organization.Id)
                           .OrderBy(_ => _.CascadeId).ToListAsync();

                organization.Pid = input.Pid;
                ChangeOrganizationModel(organization, parent);
                foreach (var org in orgs)
                {
                    if (org.Pid == organization.Id)
                    {
                        ChangeOrganizationModel(org, organization, false);
                    }
                    else
                    {
                        var orgParent = orgs.FirstOrDefault(_ => _.Id == org.Pid);
                        ChangeOrganizationModel(org, orgParent, false);
                    }
                }
            }

            organization.Name    = input.Name;
            organization.Sort    = input.Sort;
            organization.Enabled = input.Enabled;

            return(ObjectMapper.Map <Organization, OrganizationDto>(organization));
        }
Exemple #7
0
 public Task <OrganizationDto> Update(Guid id, CreateOrUpdateOrganizationDto input)
 {
     return(_organizationAppService.Update(id, input));
 }
Exemple #8
0
 public Task <OrganizationDto> Create(CreateOrUpdateOrganizationDto input)
 {
     return(_organizationAppService.Create(input));
 }