33
44using AuthPermissions . AspNetCore . ShardingServices ;
55using AuthPermissions . BaseCode . DataLayer . Classes ;
6+ using AuthPermissions . BaseCode . DataLayer . EfCode ;
67using AuthPermissions . BaseCode . SetupCode ;
78using LocalizeMessagesAndErrors ;
89using StatusGeneric ;
@@ -15,17 +16,21 @@ namespace AuthPermissions.SupportCode;
1516public class DemoGetDatabaseForNewTenant : IGetDatabaseForNewTenant
1617{
1718 private readonly IShardingConnections _shardingService ;
19+ private readonly AuthPermissionsDbContext _context ;
1820 private readonly IDefaultLocalizer _localizeDefault ;
1921
2022 /// <summary>
2123 /// ctor
2224 /// </summary>
2325 /// <param name="shardingService"></param>
26+ /// <param name="context"></param>
2427 /// <param name="localizeProvider"></param>
25- public DemoGetDatabaseForNewTenant ( IShardingConnections shardingService ,
28+ public DemoGetDatabaseForNewTenant ( IShardingConnections shardingService ,
29+ AuthPermissionsDbContext context ,
2630 IAuthPDefaultLocalizer localizeProvider )
2731 {
2832 _shardingService = shardingService ;
33+ _context = context ;
2934 _localizeDefault = localizeProvider . DefaultLocalizer ;
3035 }
3136
@@ -40,10 +45,10 @@ public DemoGetDatabaseForNewTenant(IShardingConnections shardingService,
4045 /// <param name="region">If not null this provides geographic information to pick the nearest database server.</param>
4146 /// <param name="version">Optional: provides the version name in case that effects the database selection</param>
4247 /// <returns>Status with the DatabaseInfoName, or error if it can't find a database to work with</returns>
43- public async Task < IStatusGeneric < string > > FindOrCreateDatabaseAsync ( Tenant tenant , bool hasOwnDb , string region ,
48+ public async Task < IStatusGeneric < Tenant > > FindOrCreateDatabaseAsync ( Tenant tenant , bool hasOwnDb , string region ,
4449 string version = null )
4550 {
46- var status = new StatusGenericLocalizer < string > ( _localizeDefault ) ;
51+ var status = new StatusGenericLocalizer < Tenant > ( _localizeDefault ) ;
4752
4853 //This gets the databases with the info on whether the database is available
4954 var dbsWithUsers = await _shardingService . GetDatabaseInfoNamesWithTenantNamesAsync ( ) ;
@@ -68,7 +73,11 @@ public async Task<IStatusGeneric<string>> FindOrCreateDatabaseAsync(Tenant tenan
6873 status . AddErrorString ( "NoDbForTenant" . ClassLocalizeKey ( this , true ) ,
6974 "We cannot create the tenant at this time. Please contact the support team with the code: no db available." ) ;
7075
71- return status ;
76+ //Now set up the sharding parts of the tenant
77+ tenant . UpdateShardingState ( foundDatabaseInfoName , hasOwnDb ) ;
78+ status . CombineStatuses ( await _context . SaveChangesWithChecksAsync ( _localizeDefault ) ) ;
79+
80+ return status . SetResult ( tenant ) ;
7281 }
7382
7483 /// <summary>
0 commit comments