public async Task AddPackageOwnerAsync(PackageRegistration packageRegistration, User user)
        {
            if (packageRegistration == null)
            {
                throw new ArgumentNullException(nameof(packageRegistration));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            using (var strategy = new SuspendDbExecutionStrategy())
                using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
                {
                    Func <ReservedNamespace, bool> predicate =
                        reservedNamespace => reservedNamespace.IsPrefix
                        ? packageRegistration.Id.StartsWith(reservedNamespace.Value, StringComparison.OrdinalIgnoreCase)
                        : packageRegistration.Id.Equals(reservedNamespace.Value, StringComparison.OrdinalIgnoreCase);

                    var userOwnedMatchingNamespacesForId = user
                                                           .ReservedNamespaces
                                                           .Where(predicate);

                    if (userOwnedMatchingNamespacesForId.Any())
                    {
                        if (!packageRegistration.IsVerified)
                        {
                            await _packageService.UpdatePackageVerifiedStatusAsync(new List <PackageRegistration> {
                                packageRegistration
                            }, isVerified : true);
                        }

                        userOwnedMatchingNamespacesForId
                        .ToList()
                        .ForEach(mn =>
                                 _reservedNamespaceService.AddPackageRegistrationToNamespace(mn.Value, packageRegistration));

                        // The 'AddPackageRegistrationToNamespace' does not commit its changes, so saving changes for consistency.
                        await _entitiesContext.SaveChangesAsync();
                    }

                    await _packageService.AddPackageOwnerAsync(packageRegistration, user);

                    await DeletePackageOwnershipRequestAsync(packageRegistration, user);

                    transaction.Commit();
                }

            await _auditingService.SaveAuditRecordAsync(
                new PackageRegistrationAuditRecord(packageRegistration, AuditedPackageRegistrationAction.AddOwner, user.Username));
        }
        private async Task AddPackageOwnerTask(PackageRegistration packageRegistration, User user, bool commitChanges = true)
        {
            Func <ReservedNamespace, bool> predicate =
                reservedNamespace => reservedNamespace.IsPrefix
                        ? packageRegistration.Id.StartsWith(reservedNamespace.Value, StringComparison.OrdinalIgnoreCase)
                        : packageRegistration.Id.Equals(reservedNamespace.Value, StringComparison.OrdinalIgnoreCase);

            var userOwnedMatchingNamespacesForId = user
                                                   .ReservedNamespaces
                                                   .Where(predicate);

            if (userOwnedMatchingNamespacesForId.Any())
            {
                if (!packageRegistration.IsVerified)
                {
                    await _packageService.UpdatePackageVerifiedStatusAsync(new List <PackageRegistration> {
                        packageRegistration
                    }, isVerified : true, commitChanges : commitChanges);
                }

                userOwnedMatchingNamespacesForId
                .ToList()
                .ForEach(mn =>
                         _reservedNamespaceService.AddPackageRegistrationToNamespace(mn.Value, packageRegistration));

                if (commitChanges)
                {
                    // The 'AddPackageRegistrationToNamespace' does not commit its changes, so saving changes for consistency.
                    await _entitiesContext.SaveChangesAsync();
                }
            }

            await _packageService.AddPackageOwnerAsync(packageRegistration, user, commitChanges);

            await DeletePackageOwnershipRequestAsync(packageRegistration, user, commitChanges);
        }