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

Link Users Automatically #8334


User avatar
0
maharatha created

When I am tryinhg to add an user in a tenant then I am trying to search this user in host using the email address or user name and if I get a hit I would like to link these two users automatically while creating the user in Tenant

Can you please guide where should I make this change in CreateUserAsync ?


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi @maharatha

    Try

    //link host user
    if (AbpSession.MultiTenancySide == MultiTenancySides.Tenant)
    {
    	using (CurrentUnitOfWork.SetTenantId(null))
    	{
    		_userAccountRepository.Insert(new UserAccount
    		{
    			TenantId = user.TenantId,
    			UserName = user.UserName,
    			UserId = user.Id,
    			EmailAddress = user.EmailAddress
    		});
    		await CurrentUnitOfWork.SaveChangesAsync(); 
    
    		var hostUser = await UserManager.FindByNameAsync(user.UserName) ?? await UserManager.FindByEmailAsync(user.EmailAddress);
    		if (hostUser != null)
    		{
    			await _userLinkManager.Link(user, hostUser);
    		}
    	}
    }
    

  • User Avatar
    0
    maharatha created

    Thank You it worked.