committed by
GitHub
3 changed files with 115 additions and 1 deletions
@ -0,0 +1,67 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.SettingManagement; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace LINGYUN.Abp.SettingManagement; |
|||
|
|||
[Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] |
|||
public class TimeZoneSettingsAppService : SettingManagementAppServiceBase, ITimeZoneSettingsAppService |
|||
{ |
|||
protected ISettingManager SettingManager { get; } |
|||
protected ITimezoneProvider TimezoneProvider { get; } |
|||
|
|||
private const string UnspecifiedTimeZone = "Unspecified"; |
|||
|
|||
public TimeZoneSettingsAppService(ISettingManager settingManager, ITimezoneProvider timezoneProvider) |
|||
{ |
|||
SettingManager = settingManager; |
|||
TimezoneProvider = timezoneProvider; |
|||
} |
|||
|
|||
public virtual async Task<string> GetAsync() |
|||
{ |
|||
var timezone = CurrentTenant.GetMultiTenancySide() == MultiTenancySides.Host |
|||
? await SettingManager.GetOrNullGlobalAsync(TimingSettingNames.TimeZone) |
|||
: await SettingManager.GetOrNullForCurrentTenantAsync(TimingSettingNames.TimeZone); |
|||
|
|||
if (timezone.IsNullOrWhiteSpace()) |
|||
{ |
|||
timezone = UnspecifiedTimeZone; |
|||
} |
|||
|
|||
return timezone; |
|||
} |
|||
|
|||
public virtual Task<List<NameValue>> GetTimezonesAsync() |
|||
{ |
|||
var timezones = TimeZoneHelper.GetTimezones(TimezoneProvider.GetIanaTimezones()); |
|||
timezones.Insert(0, new NameValue |
|||
{ |
|||
Name = L["DefaultTimeZone"], |
|||
Value = UnspecifiedTimeZone |
|||
}); |
|||
return Task.FromResult(timezones); |
|||
} |
|||
|
|||
public virtual async Task UpdateAsync(string timezone) |
|||
{ |
|||
if (timezone.Equals(UnspecifiedTimeZone, StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
timezone = null; |
|||
} |
|||
|
|||
if (CurrentTenant.GetMultiTenancySide() == MultiTenancySides.Host) |
|||
{ |
|||
await SettingManager.SetGlobalAsync(TimingSettingNames.TimeZone, timezone); |
|||
} |
|||
else |
|||
{ |
|||
await SettingManager.SetForCurrentTenantAsync(TimingSettingNames.TimeZone, timezone); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.SettingManagement; |
|||
|
|||
namespace LINGYUN.Abp.SettingManagement; |
|||
|
|||
[RemoteService(Name = AbpSettingManagementRemoteServiceConsts.RemoteServiceName)] |
|||
[Area(AbpSettingManagementRemoteServiceConsts.ModuleName)] |
|||
[Route("api/setting-management/timezone")] |
|||
[Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)] |
|||
public class TimeZoneSettingsController : AbpControllerBase, ITimeZoneSettingsAppService |
|||
{ |
|||
private readonly ITimeZoneSettingsAppService _service; |
|||
|
|||
public TimeZoneSettingsController(ITimeZoneSettingsAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<string> GetAsync() |
|||
{ |
|||
return _service.GetAsync(); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("timezones")] |
|||
public virtual Task<List<NameValue>> GetTimezonesAsync() |
|||
{ |
|||
return _service.GetTimezonesAsync(); |
|||
} |
|||
|
|||
[HttpPost] |
|||
public virtual Task UpdateAsync(string timezone) |
|||
{ |
|||
return _service.UpdateAsync(timezone); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue