0
BobIngham created
I am trying to introduce a new set of roles for each tenant through the Nuagecare.Migrations.Seed.SeedHelper method. How do I get all tenants in the static SeedHelper class?
public static void SeedHostDb(NuagecareDbContext context)
{
context.SuppressAutoSetTenantId = true;
//Host seed
new InitialHostDbBuilder(context).Create();
//Default tenant seed (in host database).
new DefaultTenantBuilder(context).Create();
//how do I get all tenants here?
//foreach (var tenant in tenants)....
new TenantRoleAndUserBuilder(context, tenant.id).Create();
new DefaultTenantDataBuilder(context, tenant.id).Create();
}
3 Answer(s)
-
0
-
0
Because within the method: TenantRoleAndUserBuilder(context, tenant.id).Create(); I am setting permissions and need the tenant number.:
private void CreateRolesAndUsers() { //Staff role _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Carer, StaticRoleNames.Tenants.Carer) { IsStatic = true, IsDefault = true }); var carerRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Carer); if (carerRole == null) { //Grant all permissions to admin role var permissions = PermissionFinder .GetAllPermissions(new AppAuthorizationProvider(false)) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant)) .ToList(); foreach (var permission in permissions) { if ( permission.Name == "Pages.Tenant.Dashboard" || permission.Name == "Pages.NcEntities" || permission.Name == "Pages.NcEntity.Display" || permission.Name == "Pages.NcEntity.Display.Dashboard" || permission.Name == "Pages.NcEntity.Display.Profile" || permission.Name == "Pages.NcEntity.Display.Profile.Metrics" || permission.Name == "Pages.NcEntity.NcCarePlans" || permission.Name == "Pages.NcEntity.NcCarePlan.Read" || permission.Name == "Pages.NcEntity.NcWarnings" ) { _context.Permissions.Add( new RolePermissionSetting { TenantId = _tenantId, Name = permission.Name, IsGranted = true, RoleId = carerRole.Id }); } } _context.SaveChanges(); } }
And therefore i would like to seed each tenant indivdiually.