Beispiel #1
0
        public async Task CreateAsync(AddOrEditClientDto dto)
        {
            string clientId = await CheckDuplicationClientIdAsync(dto.SubDomain);

            var entity = dto.ToEntity();

            entity.ClientId = clientId;

            entity.ClientUri = _tenantConfig.ParseClientUriBySubDomain(dto.SubDomain);

            _clients.Add(entity);

            AddClientConfiguration(entity);

            var user = new User {
                UserName = $"{dto.SubDomain}@{clientId}"
            };

            user.PasswordHash = _passwordHasher.HashPassword(user, "Admin@1234");

            _user.Add(user);

            _userClient.Add(new UserClient(user.Id, entity.Id));

            var strategy = _context.Database.CreateExecutionStrategy();

            await strategy.ExecuteAsync(async() =>
            {
                using var transaction = _context.Database.BeginTransaction();

                await _context.SaveChangesAsync();

                await SetCacheTenantProfileAsync(entity, user);

                await _proxyService.CreateTenantAsync(entity.ClientId);

                transaction.Commit();
            });
        }