public async Task <GetEditionForEditOutput> GetEditionForEdit(NullableIdDto input) { var features = FeatureManager.GetAll(); EditionEditDto editionEditDto; List <NameValue> featureValues; if (input.Id.HasValue) //Editing existing edition? { var edition = await _editionManager.FindByIdAsync(input.Id.Value); featureValues = (await _editionManager.GetFeatureValuesAsync(input.Id.Value)).ToList(); editionEditDto = edition.MapTo <EditionEditDto>(); } else { editionEditDto = new EditionEditDto(); featureValues = features.Select(f => new NameValue(f.Name, f.DefaultValue)).ToList(); } return(new GetEditionForEditOutput { Edition = editionEditDto, Features = features.MapTo <List <FlatFeatureDto> >().OrderBy(f => f.DisplayName).ToList(), FeatureValues = featureValues.Select(fv => new NameValueDto(fv)).ToList() }); }
protected virtual async Task <AbpUserFeatureConfigDto> GetUserFeaturesConfig() { var config = new AbpUserFeatureConfigDto() { AllFeatures = new Dictionary <string, AbpStringValueDto>() }; var allFeatures = FeatureManager.GetAll().ToList(); if (AbpSession.TenantId.HasValue) { var currentTenantId = AbpSession.GetTenantId(); foreach (var feature in allFeatures) { var value = await FeatureChecker.GetValueAsync(currentTenantId, feature.Name); config.AllFeatures.Add(feature.Name, new AbpStringValueDto { Value = value }); } } else { foreach (var feature in allFeatures) { config.AllFeatures.Add(feature.Name, new AbpStringValueDto { Value = feature.DefaultValue }); } } return(config); }
public async Task <GetEditionEditOutput> GetEditionForEdit([FromQuery] NullableIdDto input) { var features = FeatureManager.GetAll() .Where(f => f.Scope.HasFlag(FeatureScopes.Edition)); EditionEditDto editionEditDto; List <NameValue> featureValues; if (input.Id.HasValue && input.Id != 0) //Editing existing edition? { var edition = await _editionManager.FindByIdAsync(input.Id.Value); featureValues = (await _editionManager.GetFeatureValuesAsync(input.Id.Value)).ToList(); editionEditDto = ObjectMapper.Map <EditionEditDto>(edition); } else { editionEditDto = new EditionEditDto(); featureValues = features.Select(f => new NameValue(f.Name, f.DefaultValue)).ToList(); } var featureDtos = ObjectMapper.Map <List <FlatFeatureDto> >(features).OrderBy(f => f.DisplayName).ToList(); return(new GetEditionEditOutput { Edition = editionEditDto, Features = featureDtos, FeatureValues = featureValues.Select(fv => new NameValueDto(fv)).ToList() }); }
/// <summary> /// 获取当前账号版本信息 /// </summary> /// <returns></returns> public async Task <EditionsViewOutput> GetCurrentEdition() { var features = FeatureManager .GetAll() .Where(feature => (feature[FeatureMetadata.CustomFeatureKey] as FeatureMetadata)?.IsVisibleOnPricingTable ?? false); var flatFeatures = ObjectMapper .Map <List <FlatFeatureSelectDto> >(features) .OrderBy(f => f.DisplayName) .ToList(); var tenant = _tenantCache.Get(AbpSession.GetTenantId()); SubscribableEditionCacheItem edition; if (tenant.EditionId.HasValue) { edition = await _subscribableEditionCache.GetAsync(tenant.EditionId.Value); } else { edition = await _subscribableEditionCache.GetDefaultAsync(); } var featureDictionary = features.ToDictionary(feature => feature.Name, f => f); return(new EditionsViewOutput { AllFeatures = flatFeatures, EditionWithFeatures = await CreateEditionWithFeaturesDto(edition, featureDictionary), }); }
public async Task <EditionsSelectOutput> GetEditionsForSelect() { var features = FeatureManager .GetAll() .Where(feature => (feature[FeatureMetadata.CustomFeatureKey] as FeatureMetadata)?.IsVisibleOnPricingTable ?? false); var flatFeatures = ObjectMapper .Map <List <FlatFeatureSelectDto> >(features) .OrderBy(f => f.DisplayName) .ToList(); var editions = (await _editionManager.GetAllAsync()) .Cast <SubscribableEdition>() .OrderBy(e => e.MonthlyPrice) .ToList(); var featureDictionary = features.ToDictionary(feature => feature.Name, f => f); var editionWithFeatures = new List <EditionWithFeaturesDto>(); foreach (var edition in editions) { editionWithFeatures.Add(await CreateEditionWithFeaturesDto(edition, featureDictionary)); } if (AbpSession.UserId.HasValue) { var currentEditionId = (await _tenantManager.GetByIdAsync(AbpSession.GetTenantId())) .EditionId; if (currentEditionId.HasValue) { editionWithFeatures = editionWithFeatures.Where(e => e.Edition.Id != currentEditionId).ToList(); var currentEdition = (SubscribableEdition)(await _editionManager.GetByIdAsync(currentEditionId.Value)); var lastPayment = await _subscriptionPaymentRepository.GetLastCompletedPaymentOrDefaultAsync( AbpSession.GetTenantId(), null, null); if (lastPayment != null) { editionWithFeatures = editionWithFeatures .Where(e => e.Edition.GetPaymentAmount(lastPayment.PaymentPeriodType) > currentEdition.GetPaymentAmount(lastPayment.PaymentPeriodType) ) .ToList(); } } } return(new EditionsSelectOutput { AllFeatures = flatFeatures, EditionsWithFeatures = editionWithFeatures, }); }
public virtual async Task <IReadOnlyList <NameValue> > GetFeatureValuesAsync(int tenantId) { var values = new List <NameValue>(); foreach (var feature in FeatureManager.GetAll()) { values.Add(new NameValue(feature.Name, await GetFeatureValueOrNullAsync(tenantId, feature.Name) ?? feature.DefaultValue)); } return(values); }
public async Task <GetTenantFeaturesEditOutput> GetTenantFeaturesForEdit(EntityDto input) { var features = FeatureManager.GetAll(); var featureValues = await TenantManager.GetFeatureValuesAsync(input.Id); return(new GetTenantFeaturesEditOutput { Features = ObjectMapper.Map <List <FlatFeatureDto> >(features).OrderBy(f => f.DisplayName).ToList(), FeatureValues = featureValues.Select(fv => new NameValueDto(fv)).ToList() }); }
public virtual IReadOnlyList <NameValue> GetFeatureValues(int editionId) { var values = new List <NameValue>(); foreach (var feature in FeatureManager.GetAll()) { values.Add(new NameValue(feature.Name, GetFeatureValueOrNull(editionId, feature.Name) ?? feature.DefaultValue)); } return(values); }
public async Task <GetTenantFeaturesForEditOutput> GetTenantFeaturesForEdit(NullableIdDto input) { var features = FeatureManager.GetAll(); var featureValues = await TenantManager.GetFeatureValuesAsync(input.Id.Value); return(new GetTenantFeaturesForEditOutput { Features = features.MapTo <List <FlatFeatureDto> >().OrderBy(f => f.DisplayName).ToList(), FeatureValues = featureValues.Select(fv => new NameValueDto(fv)).ToList() }); }
public async Task <IActionResult> Assign(string type, string data) { Dictionary <string, object> Values = null; if (type == "edition") { Values = (await EditionManager.GetFeatureValuesAsync(int.Parse(data))).ToDictionary(o => o.Name, o => (object)o.Value); } else if (type == "tenant") { Values = (await TenantManager.GetFeatureValuesAsync(int.Parse(data))).ToDictionary(o => o.Name, o => (object)o.Value); } var features = FeatureManager.GetAll(); ViewData["Features"] = features; ViewData["Values"] = Values; return(View()); }
public async Task <EditionsSelectOutput> GetEditionsForSelect() { var features = FeatureManager .GetAll() .Where(feature => (feature[FeatureMetadata.CustomFeatureKey] as FeatureMetadata)?.IsVisibleOnPricingTable ?? false); var flatFeatures = ObjectMapper .Map <List <FlatFeatureSelectDto> >(features) .OrderBy(f => f.DisplayName) .ToList(); var editions = (await _editionManager.GetAllAsync()) .Cast <SubscribableEdition>() .OrderBy(e => e.MonthlyPrice) .ToList(); var featureDictionary = features.ToDictionary(feature => feature.Name, f => f); var editionWithFeatures = new List <EditionWithFeaturesDto>(); foreach (var edition in editions) { editionWithFeatures.Add(await CreateEditionWithFeaturesDto(edition, featureDictionary)); } int?tenantEditionId = null; if (AbpSession.UserId.HasValue) { tenantEditionId = (await _tenantManager.GetByIdAsync(AbpSession.GetTenantId())) .EditionId; } return(new EditionsSelectOutput { AllFeatures = flatFeatures, EditionsWithFeatures = editionWithFeatures, TenantEditionId = tenantEditionId }); }