diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/GlobalResources/GlobalResourceManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/GlobalResources/GlobalResourceManager.cs index c1834ea4ff..a95061d867 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/GlobalResources/GlobalResourceManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/GlobalResources/GlobalResourceManager.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using Volo.Abp; using Volo.Abp.Domain.Services; namespace Volo.CmsKit.GlobalResources; @@ -23,19 +22,46 @@ public class GlobalResourceManager : DomainService return await SetGlobalResourceAsync(GlobalResourceConsts.GlobalScriptName, value); } + public virtual async Task GetGlobalStyleAsync(string value) + { + return await GetOrCreateResourceAsync(GlobalResourceConsts.GlobalStyleName); + } + + public virtual async Task GetGlobalScriptAsync(string value) + { + return await GetOrCreateResourceAsync(GlobalResourceConsts.GlobalScriptName); + } + protected virtual async Task SetGlobalResourceAsync(string name, string value) { var resource = await _globalResourceRepository.FindByName(name); if (resource == null) { - return await _globalResourceRepository.InsertAsync( - new GlobalResource(GuidGenerator.Create(), name, value, CurrentTenant.Id) - ); + return await CreateResourceAsync(name, value); } resource.SetValue(value); return await _globalResourceRepository.UpdateAsync(resource); } + + protected virtual async Task GetOrCreateResourceAsync(string name) + { + var resource = await _globalResourceRepository.FindByName(name); + + if (resource == null) + { + return await CreateResourceAsync(name, string.Empty); + } + + return resource; + } + + protected virtual async Task CreateResourceAsync(string name, string value) + { + return await _globalResourceRepository.InsertAsync( + new GlobalResource(GuidGenerator.Create(), name, value, CurrentTenant.Id) + ); + } } \ No newline at end of file