public async Task Should_Create_Root_OU() { //Act await _organizationUnitManager.CreateAsync(new OrganizationUnit(AbpSession.TenantId, "Root 1")); //Assert var root1 = GetOUOrNull("Root 1"); root1.ShouldNotBeNull(); root1.Code.ShouldBe(OrganizationUnit.CreateCode(3)); }
public override async Task <OrganizationUnitDto> Create(CreateOrganizationUnitDto input) { var orgazitionUnit = ObjectMapper.Map <OrganizationUnit>(input); await _organizationUnitManager.CreateAsync(orgazitionUnit); return(ObjectMapper.Map <OrganizationUnitDto>(orgazitionUnit)); }
public async Task <OrganizationUnitDto> CreateOrganizationUnit(CreateOrganizationUnitInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); //2017.10.17:修改组织为宿主级 var organizationUnit = new OrganizationUnit(null, input.DisplayName, input.ParentId); await _organizationUnitManager.CreateAsync(organizationUnit); await CurrentUnitOfWork.SaveChangesAsync(); //todo:生产租户信息 var tenantId = await TenantManager.CreateWithAdminUserAsync(input.DisplayName, input.DisplayName, organizationUnit.Id, null, user.EmailAddress, null, true, input.EditionId, true, false, null, false, _appUrlService.CreateEmailActivationUrlFormat(input.DisplayName) ); var result = ObjectMapper.Map <OrganizationUnitDto>(organizationUnit); result.TenantId = tenantId; return(result); }
public virtual async Task <OrganizationUnitOutput> CreateOrganizationUnitAsync(CreateOrganizationUnitInput input) { await _zeroOrganizationUnitManager.CheckEnableOrganizationUnitManagement(); if (input.ParentId == null) { await _zeroOrganizationUnitManager.CheckCanAddRootOrganizationUnitAsync(); } else { var parent = await _organizationUnitRepository.GetAsync(input.ParentId.Value); await _zeroOrganizationUnitManager.CheckCanAddChildOrganizationUnitInStaticOrganizationUnitAsync(parent); await _zeroOrganizationUnitManager.CheckMaxOrganizationUnitDepthAsync(parent); } var displayName = input.DisplayName.Trim(); var entity = await _organizationUnitRepository.FirstOrDefaultAsync(o => o.DisplayName == displayName && o.ParentId == input.ParentId); if (entity != null) { throw new UserFriendlyException($"The suborganization { displayName } is duplicate!"); } entity = new ZeroOrganizationUnit { DisplayName = displayName, ParentId = input.ParentId }; await _organizationUnitManager.CreateAsync(entity); await CurrentUnitOfWork.SaveChangesAsync(); return(Map <OrganizationUnitOutput>(entity)); }
protected virtual async Task Create(CreateOrEditMdaDto input) { var mda = ObjectMapper.Map <Mda>(input); await _organizationUnitManager.CreateAsync(mda); await CurrentUnitOfWork.SaveChangesAsync(); }
public override async Task <OrganizationUnitDto> CreateAsync(CreateOrganizationUnitDto input) { var entity = await MapToEntityAsync(input); await _organizationUnitManager.CreateAsync(entity); return(await MapToGetOutputDtoAsync(entity)); }
public async Task CreateAsnyc() { await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), "Root 1")); var root1 = await _organizationUnitRepository.GetAsync("Root 1"); root1.ShouldNotBeNull(); }
protected virtual async Task Create(CreateOrEditDeliverableDto input) { var deliverable = ObjectMapper.Map <Deliverable>(input); await _organizationUnitManager.CreateAsync(deliverable); await CurrentUnitOfWork.SaveChangesAsync(); }
public async Task <OrganizationUnitListDto> Create(CreateOrganizationUnitInput input) { var organizationUnit = new OrganizationUnit(AbpSession.TenantId, input.DisplayName, input.ParentId); await _organizationUnitManager.CreateAsync(organizationUnit); await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <OrganizationUnitListDto>(organizationUnit)); }
public async Task <OrganizationUnitDto> CreateOrganizationUnit(CreateOrganizationUnitInput input) { var organizationUnit = new OrganizationUnit(AbpSession.TenantId, input.DisplayName, input.ParentId == 0 ? null : input.ParentId); await _organizationUnitManager.CreateAsync(organizationUnit); await CurrentUnitOfWork.SaveChangesAsync(); return(organizationUnit.MapTo <OrganizationUnitDto>()); }
private async Task<OrganizationUnit> CreateAndSaveOrganizationUnit(List<OrganizationUnit> organizationUnits, Tenant tenant, string displayName, OrganizationUnit parent = null) { var organizationUnit = new OrganizationUnit(tenant.Id, displayName, parent == null ? (long?)null : parent.Id); await _organizationUnitManager.CreateAsync(organizationUnit); await CurrentUnitOfWork.SaveChangesAsync(); organizationUnits.Add(organizationUnit); return organizationUnit; }
public async Task <OrganizationUnitInput> CreateAsync(OrganizationUnitInput organizationUnit) { var id = GuidGenerator.Create(); var input = new OrganizationUnit(id, organizationUnit.DisplayName, organizationUnit.ParentId, CurrentTenant.Id); organizationUnit.id = id; organizationUnit.Code = input.Code; await OrganizationUnitManager.CreateAsync(input); return(organizationUnit); }
/// <summary> /// 创建当前租户下的组织 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <OrgUnitDto> CreateAsync(CreateOrgUnitDto input) { var orgUnit = ObjectMapper.Map <OrganizationUnit>(input); orgUnit.TenantId = GetCurrentTenantId(); await _orgUnitManager.CreateAsync(orgUnit); await CurrentUnitOfWork.SaveChangesAsync(); return(await GenerateOrgUnitDtoAsync(orgUnit)); }
/// <summary> /// 运维专用:创建特定租户下的组织 /// </summary> /// <param name="tenantId"></param> /// <param name="input"></param> /// <returns></returns> public async Task <OrgUnitDto> CreateOrgUnitInTenantAsync(int tenantId, CreateOrgUnitDto input) { using (CurrentUnitOfWork.SetTenantId(tenantId)) { var orgUnit = ObjectMapper.Map <OrganizationUnit>(input); orgUnit.TenantId = tenantId; await _orgUnitManager.CreateAsync(orgUnit); //await CurrentUnitOfWork.SaveChangesAsync(); return(await GenerateOrgUnitDtoAsync(orgUnit)); } }
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)); } }
public virtual async Task <OrganizationUnitDto> CreateAsync(OrganizationUnitCreateDto input) { var origanizationUnit = new OrganizationUnit( GuidGenerator.Create(), input.DisplayName, input.ParentId, CurrentTenant.Id) { CreationTime = Clock.Now }; input.MapExtraPropertiesTo(origanizationUnit); await OrganizationUnitManager.CreateAsync(origanizationUnit); await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <OrganizationUnit, OrganizationUnitDto>(origanizationUnit)); }
private async Task SeedRandomOrganizationUnitsWithProductsAsync(int count) { for (int i = 0; i < count; i++) { var id = _guidGenerator.Create(); var ouName = CreateRandomWordWithGuid(id); using (var uow = _unitOfWorkManager.Begin()) { var ou = new OrganizationUnit(id, ouName); await _organizationUnitManager.CreateAsync(ou); await uow.CompleteAsync(); await _productManager.CreateAsync(new Product(CreateRandomWordWithGuid(id), CreateRandomFloatNumber(), ou, null)); } } }
public virtual async Task <OrganizationUnitDto> CreateAsync(OrganizationUnitCreateDto input) { var parentOrganizationUnit = input.ParentId.HasValue ? await OrganizationUnitRepository.GetAsync(input.ParentId.Value, false) : null; if (parentOrganizationUnit != null) { await AuthorizationService.CheckAsync(parentOrganizationUnit, CommonOperations.Create); } else { await AuthorizationService.CheckAsync(OrganizationUnitPermissions.OrganizationUnits.SuperAuthorization); } var children = await OrganizationUnitRepository.GetChildrenAsync(input.ParentId, false); await RepairPosition(children);// var ou = new OrganizationUnit( GuidGenerator.Create(), input.DisplayName, input.ParentId, CurrentTenant.Id); ou.SetProperty(OrganizationUnitExtraPropertyNames.IsActiveName, input.IsActive); ou.SetProperty(OrganizationUnitExtraPropertyNames.PositionName, children.Select(c => c.GetProperty <int>(OrganizationUnitExtraPropertyNames.PositionName)) .DefaultIfEmpty(0).Max() + 1); foreach (var roleId in input.RoleIds) { ou.AddRole(roleId); } await OrganizationUnitManager.CreateAsync(ou); //remove cache await CacheOrganizationUnits.RemoveAsync(AllOrganizationUnitsListCacheName); return(ObjectMapper.Map <OrganizationUnit, OrganizationUnitDto>(ou)); }
public override async Task <OrganizationUnitDto> CreateAsync(CreateUpdateOrganizationUnitDto input) { var _guid = _guidGenerator.Create(); if (input.ParentId != null) { var parent = await _organizationUnitRepository.FindAsync(input.ParentId.Value); if (parent == null) { throw new BusinessException($"Parent OrganizationUnit with Id:{input.ParentId} not found!"); } } await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guid, input.DisplayName, input.ParentId, _currentTenant.Id == null?input.TenantId: _currentTenant.Id)); var root1 = await _organizationUnitRepository.GetAsync(input.DisplayName); return(ObjectMapper.Map <OrganizationUnit, OrganizationUnitDto>(root1)); // return base.CreateAsync(input); }
public async Task <OrganizationUnitDto> CreateOrganizationUnit(CreateOrganizationUnitInput input) { var organizationUnit = new OrganizationUnitExtended(AbpSession.TenantId, input.DisplayName, input.ParentId); organizationUnit.ManagerId = input.ManagerId; organizationUnit.HasApprove = input.HasApprove; organizationUnit.Locations = new List <OrganizationLocation>(); if (input.Locations.Count > 0) { foreach (var item in input.Locations) { organizationUnit.Locations.Add(ObjectMapper.Map <OrganizationLocation>(item)); } } await _organizationUnitManager.CreateAsync(organizationUnit); await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <OrganizationUnitDto>(organizationUnit)); }
private async Task AddOrganizationUnitsAsync() { Guid ou1Id = _guidGenerator.Create(); Guid ou11Id = _guidGenerator.Create(); Guid ou12Id = _guidGenerator.Create(); await _organizationUnitManager.CreateAsync(new OrganizationUnit(ou1Id, DataConstants.Ou1Name)); await _organizationUnitManager.CreateAsync(new OrganizationUnit(ou11Id, DataConstants.Ou11Name, ou1Id)); await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), DataConstants.Ou111Name, ou11Id)); await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), DataConstants.Ou112Name, ou11Id)); await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), DataConstants.Ou113Name, ou11Id)); await _organizationUnitManager.CreateAsync(new OrganizationUnit(ou12Id, DataConstants.Ou12Name, ou1Id)); }
// public async Task<OrganizationUnitDto> CreateOrganizationUnit(CreateOrganizationUnitInput input) public async Task <OrganizationUnitDto> CreateOrganizationUnit(OrganizationUnitOutput input) { #region 111 //var organizationUnit = new OrganizationUnit(AbpSession.TenantId, input.DisplayName, input.ParentId); //await _organizationUnitManager.CreateAsync(organizationUnit); //await CurrentUnitOfWork.SaveChangesAsync(); ///============================================================ //return ObjectMapper.Map<OrganizationUnitDto>(organizationUnit); //var parent = _organizationRepository.GetAll().Where(o => o.Id == input.ParentId).FirstOrDefault(); //var organization = new Organization() //{ // TenantId = AbpSession.TenantId, // DisplayName = input.DisplayName, // ParentId = input.ParentId, // Leader = input.Leader, // IsShop = input.IsShop, // Status = input.Status //}; //if (parent != null) //{ // var temp = parent.Number + "," + parent.Id.ToString(); // organization.Number = temp; //} //else //{ // organization.Number = "0"; //} //await _organizationUnitManager.CreateAsync(organization); //await CurrentUnitOfWork.SaveChangesAsync(); // return ObjectMapper.Map<OrganizationUnitDto>(organization); //=============================== #endregion var OrganizationUnit = input.OrganizationUnit; var parent = _organizationRepository.GetAll().Where(o => o.Id == OrganizationUnit.ParentId).FirstOrDefault(); var organization = new Organization() { TenantId = AbpSession.TenantId, DisplayName = OrganizationUnit.DisplayName, ParentId = OrganizationUnit.ParentId, Leader = OrganizationUnit.Leader, IsShop = OrganizationUnit.IsShop, Status = OrganizationUnit.Status }; if (parent != null) { var temp = parent.Number + "," + parent.Id.ToString(); organization.Number = temp; } else { organization.Number = "0"; } // var data = _organizationUnitManager.CreateAsync(organization); await _organizationUnitManager.CreateAsync(organization); await CurrentUnitOfWork.SaveChangesAsync(); var data = _organizationUnitRepository.GetAll().Where(t => (t.DisplayName == input.OrganizationUnit.DisplayName)).FirstOrDefault(); int id = Convert.ToInt32(data.Id); return(OrganizationUnit); }
public async Task CreateAsync(OrganizationCreateInput input) { var organization = ObjectMapper.Map <OrganizationUnit>(input); await _organizationUnitManager.CreateAsync(organization); }
/// <inheritdoc/> public async Task CreatOrganizationUnit(OrganizationUnitDto input) { await _organizationUnitManager.CreateAsync(input.MapTo <OrganizationUnit>()); }
public async Task CreateAsync(OrganizationUnit organizationUnit) { await _entityManager.CreateAsync(organizationUnit); }
public override async Task <TenantDto> CreateAsync(CreateTenantDto input) { CheckCreatePermission(); // Create tenant var tenant = ObjectMapper.Map <Tenant>(input); //tenant.ConnectionString = input.ConnectionString.IsNullOrEmpty() // ? null // : SimpleStringCipher.Instance.Encrypt(input.ConnectionString); var defaultEdition = await _editionManager.FindByNameAsync(EditionManager.DefaultEditionName); if (defaultEdition != null) { tenant.EditionId = defaultEdition.Id; } await CheckDuplicatedPhoneNumber(input.AdminPhoneNumber); await CheckDuplicatedEmail(input.AdminEmailAddress); await _tenantManager.CreateAsync(tenant); await CurrentUnitOfWork.SaveChangesAsync(); // To get new tenant's id. // Create tenant database //_abpZeroDbMigrator.CreateOrMigrateForTenant(tenant); // We are working entities of new tenant, so changing tenant filter using (CurrentUnitOfWork.SetTenantId(tenant.Id)) { // Create static roles for new tenant CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id)); await CurrentUnitOfWork.SaveChangesAsync(); // To get static role ids // Grant all permissions to admin role var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin); await _roleManager.GrantAllPermissionsAsync(adminRole); // Create admin organization unit and set admin role var adminOrgUnit = OrganizationUnitHelper.CreateDefaultAdminOrgUnit(tenant.Id); await _orgUnitManager.CreateAsync(adminOrgUnit); await CurrentUnitOfWork.SaveChangesAsync(); // To get static organization id await _roleManager.SetOrganizationUnitsAsync(adminRole, new[] { adminOrgUnit.Id }); // Create admin user for the tenant var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, input.AdminPhoneNumber); await _userManager.InitializeOptionsAsync(tenant.Id); CheckErrors(await _userManager.CreateAsync(adminUser, User.DefaultPassword)); await CurrentUnitOfWork.SaveChangesAsync(); // To get admin user's id // Assign admin user to AdminGroup ou. await _userManager.AddToOrganizationUnitAsync(adminUser, adminOrgUnit); // Assign admin user to role! CheckErrors(await _userManager.AddToRoleAsync(adminUser, adminRole.Name)); await CurrentUnitOfWork.SaveChangesAsync(); } var dto = MapToEntityDto(tenant); await SetPhoneNumberAndEmailAddress(dto); return(dto); }