erp-platform/api/modules/Erp.Settings/Erp.Settings.Domain/Settings/SettingsSettingDefinitionProvider.cs

94 lines
3.8 KiB
C#
Raw Permalink Normal View History

2025-05-06 06:45:49 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2025-11-11 19:49:52 +00:00
using Erp.Settings.Localization;
2025-05-06 06:45:49 +00:00
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Localization;
using Volo.Abp.Settings;
2025-11-11 19:49:52 +00:00
using SettingDefinition = Erp.Settings.Entities.SettingDefinition;
2025-05-06 06:45:49 +00:00
2025-11-11 19:49:52 +00:00
namespace Erp.Settings;
2025-05-06 06:45:49 +00:00
public class SettingsDefinitionProvider : SettingDefinitionProvider
{
private readonly IRepository<SettingDefinition, Guid> repository;
2025-11-04 10:32:55 +00:00
private const char MultiValueDelimiter = '|';
2025-05-06 06:45:49 +00:00
public SettingsDefinitionProvider(IRepository<SettingDefinition, Guid> repository)
{
this.repository = repository;
}
public override void Define(ISettingDefinitionContext context)
{
repository.DisableTracking();
var settingDefinitions = repository.GetListAsync().Result;
//var settingDefinitions = AsyncHelper.RunSync(() => repository.ToListAsync());
foreach (var item in settingDefinitions.OrderBy(a => a.Order))
{
var iDescription = item.DescriptionKey.IsNullOrEmpty() ? null : L(item.DescriptionKey);
var def = new Volo.Abp.Settings.SettingDefinition(
item.Code, item.DefaultValue, L(item.NameKey), iDescription,
item.IsVisibleToClients, item.IsInherited, item.IsEncrypted)
.WithProperty(SettingsConsts.MainGroup, item.MainGroupKey)
.WithProperty(SettingsConsts.SubGroup, item.SubGroupKey)
.WithProperty(SettingsConsts.DataType, item.DataType)
.WithProperty(SettingsConsts.RequiredPermission, item.RequiredPermissionName)
.WithProperty(SettingsConsts.SelectOptions, item.SelectOptions?.ToDictionary(x => x.Key, x => L(x.Value)));
if (!item.Providers.IsNullOrEmpty())
{
2025-11-04 10:32:55 +00:00
def.Providers.AddRange(item.Providers.Split(MultiValueDelimiter));
2025-05-06 06:45:49 +00:00
}
context.Add(def);
}
}
private static ILocalizableString L(string name)
{
return new LocalizableString(typeof(SettingsResource), name);
}
}
/* Definitionlar normalde eziliyor fakat bir sebepten mevcut definitionlar ezilmezse, mevcutları alıp değiştirmek için gerekli yapı şu şekilde:
var iDescription = item.DescriptionKey.IsNullOrEmpty() ? null : L(item.DescriptionKey);
var providers = item.Providers.IsNullOrEmpty() ? new string[] { } : item.Providers.ToArray();
var def = context.GetOrNull(item.Code);
if (def == null)
{
def = new Volo.Abp.Settings.SettingDefinition(
item.Code, item.DefaultValue, L(item.NameKey), iDescription,
item.IsVisibleToClients, item.IsInherited, item.IsEncrypted)
.WithProperty(SettingsConsts.MainGroup, L(item.MainGroupKey))
.WithProperty(SettingsConsts.SubGroup, L(item.SubGroupKey))
.WithProperty(SettingsConsts.DataType, item.DataType)
.WithProperty(SettingsConsts.RequiredPermission, item.RequiredPermissionName)
.WithProperty(SettingsConsts.SelectOptions, item.SelectOptions?.ToDictionary(x => x.Key, x => L(x.Value)))
.WithProviders(providers);
context.Add(def);
}
else
{
def.DefaultValue = item.DefaultValue;
def.DisplayName = L(item.NameKey);
def.Description = iDescription;
def.IsVisibleToClients = item.IsVisibleToClients;
def.IsInherited = item.IsInherited;
def.IsEncrypted = item.IsEncrypted;
def.Properties.Clear();
def.Providers.Clear();
def.WithProperty(SettingsConsts.MainGroup, L(item.MainGroupKey))
.WithProperty(SettingsConsts.SubGroup, L(item.SubGroupKey))
.WithProperty(SettingsConsts.DataType, item.DataType)
.WithProperty(SettingsConsts.RequiredPermission, item.RequiredPermissionName)
.WithProperty(SettingsConsts.SelectOptions, item.SelectOptions?.ToDictionary(x => x.Key, x => L(x.Value)))
.WithProviders(providers);
}
*/
2025-11-11 19:49:52 +00:00