Ejemplo n.º 1
0
        public virtual async Task SetEditionFeatureValueAsync(int editionId, string featureName, string value)
        {
            if (await GetEditionValueOrNullAsync(editionId, featureName) == value)
            {
                return;
            }

            var currentFeature = await _editionFeatureRepository.FirstOrDefaultAsync(f => f.EditionId == editionId && f.Name == featureName);

            var feature = _featureManager.GetOrNull(featureName);

            if (feature == null || feature.DefaultValue == value)
            {
                if (currentFeature != null)
                {
                    await _editionFeatureRepository.DeleteAsync(currentFeature);
                }

                return;
            }

            if (currentFeature == null)
            {
                await _editionFeatureRepository.InsertAsync(new EditionFeatureSetting(editionId, featureName, value));
            }
            else
            {
                currentFeature.Value = value;
            }
        }
        public virtual async Task SetEditionFeatureValueAsync(int editionId, string featureName, string value)
        {
            await _unitOfWorkManager.WithUnitOfWorkAsync(async() =>
            {
                using (_unitOfWorkManager.Current.EnableFilter(AbpDataFilters.MayHaveTenant))
                    using (_unitOfWorkManager.Current.SetTenantId(null))
                    {
                        if (await GetEditionValueOrNullAsync(editionId, featureName) == value)
                        {
                            return;
                        }

                        var currentFeature = await _editionFeatureRepository.FirstOrDefaultAsync(f => f.EditionId == editionId && f.Name == featureName);

                        var feature = _featureManager.GetOrNull(featureName);
                        if (feature == null || feature.DefaultValue == value)
                        {
                            if (currentFeature != null)
                            {
                                await _editionFeatureRepository.DeleteAsync(currentFeature);
                            }

                            return;
                        }

                        if (!feature.InputType.Validator.IsValid(value))
                        {
                            throw new UserFriendlyException(string.Format(
                                                                L("InvalidFeatureValue"), feature.Name));
                        }

                        if (currentFeature == null)
                        {
                            await _editionFeatureRepository.InsertAsync(new EditionFeatureSetting(editionId, featureName, value));
                        }
                        else
                        {
                            currentFeature.Value = value;
                        }
                    }
            });
        }
Ejemplo n.º 3
0
 public void Should_Not_Get_Undefined_Features()
 {
     _featureManager.GetOrNull("NonExistingFeature").ShouldBe(null);
     Assert.Throws <AbpException>(() => _featureManager.Get("NonExistingFeature"));
 }
Ejemplo n.º 4
0
 public void ShouldNotGetUndefinedFeatures()
 {
     featureManager.GetOrNull("NonExistingFeature").ShouldBe(null);
     Assert.Throws <StudioXException>(() => featureManager.Get("NonExistingFeature"));
 }