public void Create() { new TestOrganizationUnitsBuilder(_context, _tenantId).Create(); new TestSubscriptionPaymentBuilder(_context, _tenantId).Create(); new TestEditionsBuilder(_context).Create(); _context.SaveChanges(); }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
private OrganizationUnit CreateOrganizationUnit(string displayName, string code, long?parentId = null) { var organizationUnit = _context.OrganizationUnits.Add(new OrganizationUnit(_tenantId, displayName, parentId) { Code = code }).Entity; _context.SaveChanges(); return(organizationUnit); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
private void CreateDefaultTenant() { //Default tenant var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == MultiTenancy.Tenant.DefaultTenantName); if (defaultTenant == null) { defaultTenant = new MultiTenancy.Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName); var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition != null) { defaultTenant.EditionId = defaultEdition.Id; } _context.Tenants.Add(defaultTenant); _context.SaveChanges(); } }
private void CreateEditions() { var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition == null) { defaultEdition = new SubscribableEdition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName }; _context.Editions.Add(defaultEdition); _context.SaveChanges(); /* Add desired features to the standard edition, if wanted... */ } if (defaultEdition.Id > 0) { CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.ChatFeature, true); CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToTenantChatFeature, true); CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToHostChatFeature, true); } }
private void CreateRolesAndUsers() { //Admin role var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin); if (adminRole == null) { adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin) { IsStatic = true }).Entity; _context.SaveChanges(); } //User role var userRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.User); if (userRole == null) { _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.User, StaticRoleNames.Tenants.User) { IsStatic = true, IsDefault = true }); _context.SaveChanges(); } //admin user var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName); if (adminUser == null) { adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**"); adminUser.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe"); adminUser.IsEmailConfirmed = true; adminUser.ShouldChangePasswordOnNextLogin = false; adminUser.IsActive = true; _context.Users.Add(adminUser); _context.SaveChanges(); //Assign Admin role to admin user _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id)); _context.SaveChanges(); //User account of admin user if (_tenantId == 1) { _context.UserAccounts.Add(new UserAccount { TenantId = _tenantId, UserId = adminUser.Id, UserName = AbpUserBase.AdminUserName, EmailAddress = adminUser.EmailAddress }); _context.SaveChanges(); } //Notification subscription _context.NotificationSubscriptions.Add(new NotificationSubscriptionInfo(SequentialGuidGenerator.Instance.Create(), _tenantId, adminUser.Id, AppNotificationNames.NewUserRegistered)); _context.SaveChanges(); } }