Пример #1
0
        public async Task RollbackAsync(string tenantId)
        {
            var subscriptions = await _subscriptionRepository.GetAll().Where(x => x.TenantId == tenantId).ToListAsync();

            _subscriptionRepository.Delete(subscriptions);
            await _subscriptionRepository.CommitAsync();


            var companySettings = await _companySettingsRepository.GetAll().Where(x => x.TenantId == tenantId).ToListAsync();

            _companySettingsRepository.Delete(companySettings);
            await _companySettingsRepository.CommitAsync();

            var companies = await _companyRepository.GetAll().Where(x => x.TenantId == tenantId).ToListAsync();

            _companyRepository.Delete(companies);
            await _companyRepository.CommitAsync();

            var branches = await _branchRepository.GetAll().Where(x => x.TenantId == tenantId).ToListAsync();

            _branchRepository.Delete(branches);
            await _branchRepository.CommitAsync();

            var warehouses = await _warehouseRepository.GetAll().Where(x => x.TenantId == tenantId).ToListAsync();

            _warehouseRepository.Delete(warehouses);
            await _warehouseRepository.CommitAsync();

            #region Security

            var users = _userService.GetUsersByTenantId(tenantId);

            foreach (var user in users)
            {
                await _userService.DeleteUserAsync(user);
            }

            #endregion


            var tenants = await _tenantRepository.GetAll().Where(x => x.Id == tenantId).ToListAsync();

            _tenantRepository.Delete(tenants);
            await _tenantRepository.CommitAsync();
        }