-
Notifications
You must be signed in to change notification settings - Fork 83
/
RegionService.cs
39 lines (32 loc) · 1.32 KB
/
RegionService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Microsoft.Extensions.Localization;
using OrchardCore.Commerce.Abstractions;
using OrchardCore.Commerce.AddressDataType;
using OrchardCore.Commerce.Models;
using OrchardCore.Entities;
using OrchardCore.Settings;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace OrchardCore.Commerce.Services;
public class RegionService : IRegionService
{
private readonly ISiteService _siteService;
private readonly IStringLocalizer<RegionService> T;
public RegionService(ISiteService siteService, IStringLocalizer<RegionService> stringLocalizer)
{
_siteService = siteService;
T = stringLocalizer;
}
public IEnumerable<Region> GetAllRegions() =>
#pragma warning disable CS0618
Regions.All.Select(region => region with { DisplayName = T[region.EnglishName] });
#pragma warning restore CS0618
public async Task<IEnumerable<Region>> GetAvailableRegionsAsync()
{
var settings = await _siteService.GetSiteSettingsAsync();
var allowedRegionCodes = (settings.As<RegionSettings>()?.AllowedRegions ?? Enumerable.Empty<string>()).AsList();
var allRegions = GetAllRegions();
if (!allowedRegionCodes.Any()) return allRegions;
return allRegions.Where(region => allowedRegionCodes.Contains(region.TwoLetterISORegionName));
}
}