public virtual async Task SetFeatureValueAsync(Tenant tenant, string featureName, string value) { //触发用户权限缓存清除 Resolve <IEventBus>().Trigger(new UserGrantedPermissionIndicator { TenantId = tenant.Id }); //No need to change if it's already equals to the current value if (await GetFeatureValueOrNullAsync(tenant.Id, featureName) == value) { return; } //Get the current feature setting TenantFeatureSetting currentSetting; using (UnitOfWorkManager.Current.SetTenantId(tenant.Id)) { currentSetting = await TenantFeatureRepository.FirstOrDefaultAsync(f => f.Name == featureName); } //Get the feature var feature = FeatureManager.GetOrNull(featureName); if (feature == null) { if (currentSetting != null) { await TenantFeatureRepository.DeleteAsync(currentSetting); } return; } //Determine default value var defaultValue = tenant.EditionId.HasValue ? (await Resolve <EditionManager>().GetFeatureValueOrNullAsync(tenant.EditionId.Value, featureName) ?? feature.DefaultValue) : feature.DefaultValue; //No need to store value if it's default if (value == defaultValue) { if (currentSetting != null) { await TenantFeatureRepository.DeleteAsync(currentSetting); } return; } //Insert/update the feature value if (currentSetting == null) { await TenantFeatureRepository.InsertAsync(new TenantFeatureSetting(tenant.Id, featureName, value)); } else { currentSetting.Value = value; } }
public virtual async Task SetFeatureValueAsync(int editionId, string featureName, string value) { if (await GetFeatureValueOrNullAsync(editionId, featureName) == value) { return; } var currentSetting = await EditionFeatureRepository.FirstOrDefaultAsync(f => f.EditionId == editionId && f.Name == featureName); var feature = FeatureManager.GetOrNull(featureName); if (feature == null || feature.DefaultValue == value) { if (currentSetting != null) { await EditionFeatureRepository.DeleteAsync(currentSetting); } return; } if (currentSetting == null) { await EditionFeatureRepository.InsertAsync(new EditionFeatureSetting(editionId, featureName, value)); } else { currentSetting.Value = value; } }
public virtual void SetFeatureValue(TTenant tenant, string featureName, string value) { UnitOfWorkManager.WithUnitOfWork(() => { //No need to change if it's already equals to the current value if (GetFeatureValueOrNull(tenant.Id, featureName) == value) { return; } //Get the current feature setting TenantFeatureSetting currentSetting; using (UnitOfWorkManager.Current.EnableFilter(AbpDataFilters.MayHaveTenant)) using (UnitOfWorkManager.Current.SetTenantId(tenant.Id)) { currentSetting = TenantFeatureRepository.FirstOrDefault(f => f.Name == featureName); } //Get the feature var feature = FeatureManager.GetOrNull(featureName); if (feature == null) { if (currentSetting != null) { TenantFeatureRepository.Delete(currentSetting); } return; } //Determine default value var defaultValue = tenant.EditionId.HasValue ? (EditionManager.GetFeatureValueOrNull(tenant.EditionId.Value, featureName) ?? feature.DefaultValue) : feature.DefaultValue; //No need to store value if it's default if (value == defaultValue) { if (currentSetting != null) { TenantFeatureRepository.Delete(currentSetting); } return; } //Insert/update the feature value if (currentSetting == null) { TenantFeatureRepository.Insert(new TenantFeatureSetting(tenant.Id, featureName, value)); } else { currentSetting.Value = value; } }); }
public virtual async Task SetFeatureValueAsync(TTenant tenant, string featureName, string value) { //No need to change if it's already equals to the current value if (await GetFeatureValueOrNullAsync(tenant.Id, featureName) == value) { return; } //Get the current feature setting var currentSetting = await TenantFeatureRepository.FirstOrDefaultAsync(f => f.TenantId == tenant.Id && f.Name == featureName); //Get the feature var feature = FeatureManager.GetOrNull(featureName); if (feature == null) { if (currentSetting != null) { await TenantFeatureRepository.DeleteAsync(currentSetting); } return; } //Determine default value var defaultValue = tenant.EditionId.HasValue ? (await EditionManager.GetFeatureValueOrNullAsync(tenant.EditionId.Value, featureName) ?? feature.DefaultValue) : feature.DefaultValue; //No need to store value if it's default if (value == defaultValue) { if (currentSetting != null) { await TenantFeatureRepository.DeleteAsync(currentSetting); } return; } //Insert/update the feature value if (currentSetting == null) { await TenantFeatureRepository.InsertAsync(new TenantFeatureSetting(tenant.Id, featureName, value)); } else { currentSetting.Value = value; } }