Hello. I have created a new endpoint for creating subscribers and their self-registration. Their task is to create an edition and create a subscriber based on it.
Here is the code when I create a subscriber from the admin panel. It works fine:
CreateTenantWithCustomEditionInput https://pastebin.com/ELDFV53j CreateTenantWithCustomEdition https://pastebin.com/ZFL7KqDc
TenantManager -> CreateWithAdminUserAsync: https://pastebin.com/1fcv4DyR
I edited the new tenant registration method and I get an error writing to the database: RegisterTenantWithCustomEditionInput: https://pastebin.com/YGqcweWg
TenantRegistrationAppService -> RegisterTenantWithCustomEdition https://pastebin.com/azU2UfuU
TenantManager -> RegisterWithAdminUserAsync: https://pastebin.com/yTMfBAxn
In "RegisterWithAdminUserAsync" after "await CreateAsync(tenant);" there is a write to the database using the method "await _unitOfWorkManager.Current.SaveChangesAsync();". In this line I get an error:
Logs:
https://pastebin.com/JJszFELE
I've tried to solve the problem myself, but I've been struggling for almost a month now and I have to release the app by the end of the year and I'm at a loss. Can you tell me what might be wrong?
2 Answer(s)
-
0
Hi @Adrian,
I think this problem is related to the unit of work. You have a pending transaction in your code however, I could not determine exactly where it was. Please check your database operations and async methods
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Solved. In
RegisterTenantWithCustomEdition:public async Task<RegisterTenantOutput> RegisterTenantWithCustomEdition(RegisterTenantWithCustomEditionInput input) { List<NameValueDto> featureValues = new List<NameValueDto>(); if (input.FleetFeature) featureValues.Add(new NameValueDto(AppFeatures.Fleet, "true")); if (input.FieldServiceFeature) featureValues.Add(new NameValueDto(AppFeatures.FieldService, "true")); if (input.WorkingTimeFeature) featureValues.Add(new NameValueDto(AppFeatures.WorkingTime, "true")); if (featureValues.Count() == 0) throw new UserFriendlyException(L("SelectMinimumOneFeature")); if (input.MaxUserCount <= 0) throw new UserFriendlyException(L("NumberOfUsersMustBeGreaterThanZero")); if (input.MaxTeamMemberCount < 0) throw new UserFriendlyException(L("NumberOfTeamMembersMustEqualOrBeGreaterThanZero")); SubscribableEdition edition = null; using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew)) { using (_unitOfWorkManager.Current.SetTenantId(null)) { edition = await _editionManager.CreateDynamicEdition(featureValues.Select(x => ObjectMapper.Map<NameValue>(x)).ToList(), input.MaxTeamMemberCount, input.MaxUserCount); } await uow.CompleteAsync(); } CheckTenantRegistrationIsEnabled(); var isEmailConfirmationRequired = await SettingManager.GetSettingValueForApplicationAsync<bool>( AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin ); var tenantId = (int?)null; using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew)) { using (_unitOfWorkManager.Current.SetTenantId(null)) { tenantId = await TenantManager.RegisterWithAdminUserAsync(input.TenancyName, input.Name, input.AdminPassword, input.AdminEmailAddress, null, false, edition.Id, false, true, Clock.Now.AddDays(edition.TrialDayCount ?? 0), true, AppUrlService.CreateEmailActivationUrlFormat(input.TenancyName), adminName: input.AdminName, adminSurname: input.AdminSurname ); } await uow.CompleteAsync(); } var tenant = await TenantManager.GetByIdAsync(tenantId.Value); await _appNotifier.NewTenantRegisteredAsync(tenant); return new RegisterTenantOutput { TenantId = tenant.Id, TenancyName = input.TenancyName, Name = input.Name, UserName = AbpUserBase.AdminUserName, EmailAddress = input.AdminEmailAddress, IsActive = tenant.IsActive, IsEmailConfirmationRequired = isEmailConfirmationRequired, IsTenantActive = tenant.IsActive }; }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)