예제 #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();
        }
        public CompanySettingsViewModel GetByCompanyId(string companyId)
        {
            var companySettings = _repository.GetAll().FirstOrDefault(x => x.CompanyId == companyId);

            if (companySettings == null)
            {
                var company = _companyRepository.GetById(companyId);

                var tenantCompanySettingsId = _tenantManager.CreateTenantCompanySettings(company.TenantId, company);

                companySettings = _repository.GetById(tenantCompanySettingsId);
            }

            var viewModel = (CompanySettingsViewModel)Activator.CreateInstance(typeof(CompanySettingsViewModel),
                                                                               companySettings);

            return(viewModel);
        }