コード例 #1
0
        public async Task <string> Create(CreateTenantInput input)
        {
            var exsitTenant = await _tenantRepository.FirstOrDefaultAsync(p => p.Name == input.Name.Trim());

            if (exsitTenant != null)
            {
                throw new BusinessException($"已经存在{input.Name}的租户");
            }

            var corporationAppServiceProxy = GetService <ICorporationAppService>();

            await UnitOfWorkAsync(async (conn, trans) =>
            {
                var tenantId = await _tenantRepository.InsertAndGetIdAsync(input.MapTo <Tenant>(), conn, trans);
                if (input.CreateSuper)
                {
                    await CreateAdminAndRole(tenantId, input, conn, trans);
                }

                await corporationAppServiceProxy.CreateByTenant(new CreateCorporationByTenantInput()
                {
                    Name           = input.Name,
                    Identification = input.Identification,
                    ParentId       = 0,
                    OpenDate       = DateTime.Now,
                    RegisterDate   = DateTime.Now,
                    Mold           = CorporationMold.Group,
                    TenantId       = tenantId
                });
            }, Connection);

            return("新增租户成功");
        }
コード例 #2
0
        public async Task CreateTenant(CreateTenantInput input)
        {
            //Create tenant
            var tenant = input.MapTo <Tenant>();

            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;
            }

            CheckErrors(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 user for the tenant
                var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword);
                CheckErrors(await UserManager.CreateAsync(adminUser));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

                //Assign admin user to role!
                CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
                await CurrentUnitOfWork.SaveChangesAsync();

                //Assign Default Theme
                await _settingStore.CreateAsync(Settings.ThemeInitialConfig(tenant.Id));

                var theme = await _themeProvider.GetThemeByThemeName(ValueConst.MainTheme, HttpContext.Current.Server);

                _pymeProvider.SetMainPageContent(theme, false);
                //Paypal config
                await _settingStore.CreateAsync(Settings.PayPalInitialConfig(tenant.Id));

                await _settingStore.CreateAsync(Settings.PayPalSecretKey(tenant.Id));
            }
        }
コード例 #3
0
        /// <summary>
        /// 创建租户
        /// </summary>
        /// <param name="input">输入模型</param>
        /// <returns></returns>
        public async Task CreateTenant(CreateTenantInput input)
        {
            //Create tenant
            //创建租户
            var tenant = input.MapTo <Tenant>();

            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;
            }

            //CheckErrors(await TenantManager.CreateAsync(tenant));
            await TenantManager.CreateAsync(tenant);    //2017-05-10:新加的语句

            await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id. 获取新租户的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 获取静态角色的Id

                //grant all permissions to admin role
                //授予管理员角色的所有权限
                var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);
                await _roleManager.GrantAllPermissionsAsync(adminRole);

                //Create admin user for the tenant
                //为租户创建管理员用户
                var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword);
                CheckErrors(await UserManager.CreateAsync(adminUser));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id 获取管理员用户的Id

                //Assign admin user to role!
                //将管理员用户分配给角色
                CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
                await CurrentUnitOfWork.SaveChangesAsync();
            }
        }
コード例 #4
0
        public async Task CreateTenant(CreateTenantInput input)
        {
            //Create tenant
            var tenant = input.MapTo <Tenant>();

            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;
            }

            CheckErrors(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 user for the tenant
                var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword);
                CheckErrors(await UserManager.CreateAsync(adminUser));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

                //Assign admin user to role!
                CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
                await CurrentUnitOfWork.SaveChangesAsync();
            }

            //await _tenantManager.CreateWithAdminUserAsync(input.TenancyName,
            //    input.Name,
            //    input.AdminPassword,
            //    input.AdminEmailAddress,
            //    input.IsActive,
            //    input.EditionId,
            //    input.ShouldChangePasswordOnNextLogin,
            //    input.SendActivationEmail);
        }