Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "SorenRomer"

I found the issue to be in one of the imported css files

I found issue - sort of.... If I avoid calling EventBus.Trigger(new CustomEvent { Id = user.Id}); the tenantId is reset to the correct value after the using is disposed. Calling await EventBus.TriggerAsync(new CustomEvent { Id = user.Id}); results in the same behaviour.

I don't understand this behaviour of the EventBus? Why does it stick to tenantid null when it is being called after the using is disposed?

Wrapping the call to the eventbus inside its own using solves the problem:

using (_unitOfWorkManager.Current.SetTenantId(AbpSession.GetTenantId()))
{
    await EventBus.TriggerAsync(new CustomEvent { Id = user.Id});
}

Hi @ismcagdas, Sure thing, I kept the DoCustomStuffAsync naming:

[UnitOfWork]
[AbpAuthorize(AppPermissions.Pages_Administration_Users_Edit)]
protected virtual async Task UpdateUserAsync(CreateOrUpdateUserInput input)
{
    Debug.Assert(input.User.Id != null, "input.User.Id should be set.");

    var user = await UserManager.GetUserByIdAsync(input.User.Id.Value);

    //Update user properties
    ObjectMapper.Map(input.User, user); //Passwords is not mapped (see mapping configuration)

    // CUSTOM CODE 
    // _unitOfWorkManager.Current.GetTenantId() is **1** at this point.
    if (input.AssignedCourseId != null && AbpSession.MultiTenancySide != Abp.MultiTenancy.MultiTenancySides.Host)
    {
        await DoCustomStuffAsync(input, user);
    }
     // _unitOfWorkManager.Current.GetTenantId() is **null** at this point.

    CheckErrors(await UserManager.UpdateAsync(user));

    if (input.SetRandomPassword)
    {
        var randomPassword = await _userManager.CreateRandomPassword();
        user.Password = _passwordHasher.HashPassword(user, randomPassword);
        input.User.Password = randomPassword;
    }
    else if (!input.User.Password.IsNullOrEmpty())
    {
        await UserManager.InitializeOptionsAsync(AbpSession.TenantId);
        CheckErrors(await UserManager.ChangePasswordAsync(user, input.User.Password));
    }

    //Update roles
    CheckErrors(await UserManager.SetRolesAsync(user, input.AssignedRoleNames));

    //update organization units
    await UserManager.SetOrganizationUnitsAsync(user, input.OrganizationUnits.ToArray());

    if (input.SendActivationEmail)
    {
        user.SetNewEmailConfirmationCode();
        await _userEmailer.SendEmailActivationLinkAsync(
            user,
            AppUrlService.CreateEmailActivationUrlFormat(AbpSession.TenantId),
            input.User.Password
        );
    }
}

Here is a simplified version of the custom method:

[UnitOfWork]
private async Task DoCustomStuffAsync(CreateOrUpdateUserInput input, User user)
{
    if (input.CustomEnityId != null)
    {
        using (_unitOfWorkManager.Current.SetTenantId(null))
        {
        // GETTING GENERAL DATA FROM HOST
            var _customEntities = _customEntityRepository.GetAllIncluding(c => c.CourseFlows).FirstOrDefault(c => c.Id == (int)input.AssignedCourseId);

        // CODE REMOVED FOR CLARITY
        }

        EventBus.Trigger(new CustomEvent { Id = user.Id});
    }
    else
    {
        Logger.Info($"User {user.UserName} is not assigned to a custom entity");
    }
}

Thanks in advance

Showing 1 to 3 of 3 entries