You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.3 KiB
C#

using JetBrains.Annotations;
using Volo.Abp.Settings;
namespace NPin.Framework.SettingManagement.Domain.Provider.Extensions;
public static class TenantSettingManagerExtensions
{
public static Task<string?> GetOrNullForTenantAsync(this ISettingManager settingManager, [NotNull] string name,
Guid tenantId, bool fallback = true)
{
return settingManager.GetOrNullAsync(name, TenantSettingValueProvider.ProviderName, tenantId.ToString(),
fallback);
}
public static Task<string?> GetOrNullForCurrentTenantAsync(this ISettingManager settingManager,
[NotNull] string name, bool fallback = true)
{
return settingManager.GetOrNullAsync(name, TenantSettingValueProvider.ProviderName, null, fallback);
}
public static Task<List<SettingValue>> GetAllForTenantAsync(this ISettingManager settingManager, Guid tenantId,
bool fallback = true)
{
return settingManager.GetAllAsync(TenantSettingValueProvider.ProviderName, tenantId.ToString(), fallback);
}
public static Task<List<SettingValue>> GetAllForCurrentTenantAsync(this ISettingManager settingManager,
bool fallback = true)
{
return settingManager.GetAllAsync(TenantSettingValueProvider.ProviderName, null, fallback);
}
public static Task SetForTenantAsync(this ISettingManager settingManager, Guid tenantId, [NotNull] string name,
string? value, bool forceToSet = false)
{
return settingManager.SetAsync(name, value, TenantSettingValueProvider.ProviderName, tenantId.ToString(),
forceToSet);
}
public static Task SetForCurrentTenantAsync(this ISettingManager settingManager, [NotNull] string name,
string? value, bool forceToSet = false)
{
return settingManager.SetAsync(name, value, TenantSettingValueProvider.ProviderName, null, forceToSet);
}
public static Task SetForTenantOrGlobalAsync(this ISettingManager settingManager, Guid? tenantId,
[NotNull] string name, string? value, bool forceToSet = false)
{
return tenantId.HasValue
? settingManager.SetForTenantAsync(tenantId.Value, name, value, forceToSet)
: settingManager.SetGlobalAsync(name, value);
}
}