Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Filling default data in tables when tenant creating #1389


User avatar
0
vitaly created

Sorry for asking, couldn't find where I can write code to fill default data in some tables for tenant when new tenant is creating. Pls help.


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    If you are asking for module zero startup template, then it's defined in TenantAppService. We are also filling some data when tenant is being created. See the code: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/blob/master/src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/TenantAppService.cs#L72">https://github.com/aspnetboilerplate/mo ... ice.cs#L72</a>

  • User Avatar
    0
    vitaly created

    Is this the same in case (a) Tenant is created manually from Host (b) Tenant is created by user from landing page?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Both places use TenantManager's CreateWithAdminUserAsync method. You can do it in that method.

  • User Avatar
    0
    daws created

    FYI, i created a console project to create multiple tenant at once.

    my code look like this :

    const string tenantConnectionString = "Data Source=XXXXXXXX;Integrated Security=False;User ID=XXXXXXXXX;Password=XXXXXXXX;Initial Catalog=XXXXXXXXX;";
    var tenantId = _tenantManager.CreateWithAdminUserAsync("XXXXX", "XXXXXXX", "XXXXXXX", "xxxxxxxxxxx", xXXXXXX, true, null, false, false).Result;
    
    SeedXXXX(tenantId);
    
    
    protected void SeedXXXX(int tenantId)
            {
                using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
                {
                    using (_unitOfWorkManager.Current.SetTenantId(tenantId))
                    {
                        var context = _unitOfWorkManager.Current.GetDbContext<XXXXXDbContext>();
    
                        new XXXXXXDbBuilder(context).Create();
                        _unitOfWorkManager.Current.SaveChanges();
    
                    }
                    uow.Complete();
                }
            }
    

    yup, maybe I need to clean a little bit my code, i'm not yet a pro of unitofwork ;)