Base solution for your next web application
Open Closed

Bulk User Import #7064


User avatar
0
northwood created

I am attempting to create a simple console app to add users to a multitenancy app. We have several customers (tenants) that each have several hundred users and manually entering them in the web app is not going to happen. I'd like to just implement the CreateOrUpdateUser function in the UserAppService, but am having trouble constructing it. Can you provide step by step instructions for this task or possible include a code sample?

Thanks Adam


7 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Related: https://docs.aspnetzero.com/documents/aspnet-core-angular/latest/Features-Angular-User-Management#excel-operations

  • User Avatar
    0
    maliming created
    Support Team

    You can refer to the Migrator or AbpEfConsoleApp project, Then inject the relevant services

    or Import users from excel/csv https://github.com/aspnetzero/aspnet-zero-core/issues/1701

  • User Avatar
    0
    northwood created

    Regarding aaron's response; My understanding is that function is only available in the angular project. We are using MVC/jQuery.

    Regarding maliming's response. I attempted this approach, but am getting an exception when initializing the bootstrapper. Sample code and stack trace are below.

    Sample: //Bootstrapping ABP system using (var bootstrapper = AbpBootstrapper.Create<CustomerPortalApplicationModule>()) { // logging bootstrapper.IocManager.IocContainer .AddFacility<LoggingFacility>(f => f.UseAbpLog4Net() .WithConfig("log4net.config") ); //initialize the Abp system

                bootstrapper.Initialize(); // **error thrown here**
                // get the tenant
                int? tenantId = null;
                using (var tenantService = bootstrapper.IocManager.ResolveAsDisposable&lt;TenantAppService&gt;())
                {
                    Tenant t = await tenantService.Object.TenantManager.FindByTenancyNameAsync(tenantName);
                    tenantId = t.Id;
                }
    
                //Getting the user app service to create the user and send notifications.
                using (var userAppService = bootstrapper.IocManager.ResolveAsDisposable&lt;UserAppService&gt;())
                {
                    // set the tenant id.
                    userAppService.Object.AbpSession.Use(tenantId, 0);
                    foreach (string email in emails)
                    {
                        await userAppService.Object.CreateOrUpdateUser(BuildInput(email));
                    }
                } //Disposes user app service and all it's dependencies
    
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
            }
            
    

    Stack trace: Can't create component 'Abp.BackgroundJobs.BackgroundJobStore' as it has dependencies to be satisfied.

    'Abp.BackgroundJobs.BackgroundJobStore' is waiting for the following dependencies:

    • Service 'Abp.Domain.Repositories.IRepository`2[[Abp.BackgroundJobs.BackgroundJobInfo, Abp, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null],[System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' which was not registered.

      at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency() at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments) at Castle.Windsor.WindsorContainer.ResolveT at Abp.Dependency.IocManager.ResolveT at Abp.AbpKernelModule.PostInitialize() at Abp.Modules.AbpModuleManager.<>c.

  • User Avatar
    0
    maliming created
    Support Team

    @northwood

    Try to depend on other modules in your module.

    see: https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Migrator/AbpZeroTemplateMigratorModule.cs#L13

  • User Avatar
    0
    northwood created

    This link results in a $)$, can you provide more detail in your answer?

  • User Avatar
    0
    northwood created

    sorry 404, not $)$

  • User Avatar
    0
    maliming created
    Support Team

    Notice You can invite anyone to become a member of the ASP.NET Zero organization using their GitHub username. And they can access the ASP.NET Zero private GitHub repositories. Your license plan allows you to add up to 3 users. Right after you add a GitHub user, the user will receive an invitation email. If there is problem receiving the invitation email, alternatively user can visit github.com/orgs/aspnetzero page and accept the invitation.