SHA256
- Added DocumentNumber validations. - Added new page to see GuestDocument details.
97 lines
3.6 KiB
C#
97 lines
3.6 KiB
C#
using Microsoft.Extensions.Localization;
|
|
using Somnia.GuestLog.Resources;
|
|
|
|
namespace Somnia.GuestLog.Services;
|
|
|
|
public class StaticDataListService(
|
|
IServiceProvider serviceProvider
|
|
) : IDataListService
|
|
{
|
|
|
|
private IStringLocalizer<DataListLocale> _dataListLang
|
|
{
|
|
get
|
|
{
|
|
return serviceProvider.GetRequiredService<IStringLocalizer<DataListLocale>>();
|
|
}
|
|
}
|
|
|
|
private readonly Dictionary<string, HashSet<string>> dataListDict = new([
|
|
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_DocumentTypes, _documentTypeSet),
|
|
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_GenderOptions, _genderOptionSet),
|
|
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_CountryCodes, _countryCodeSet),
|
|
]);
|
|
|
|
public List<string> GetAvailableLists()
|
|
{
|
|
return [.. dataListDict.Keys];
|
|
}
|
|
public HashSet<string> GetDataListByName(string dataListName)
|
|
{
|
|
if (!dataListDict.TryGetValue(dataListName, out HashSet<string>? list))
|
|
{
|
|
throw new InvalidOperationException($"DataList not found with name: '{dataListName}'");
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public bool IsValueInList(string dataListName, string value)
|
|
{
|
|
var set = GetDataListByName(dataListName);
|
|
return set.Contains(value);
|
|
}
|
|
|
|
public string GetLocalizedValue(string dataListName, string? value)
|
|
{
|
|
return _dataListLang[$"dataList.{dataListName}.{value}"];
|
|
}
|
|
|
|
|
|
#region DataList Dicts
|
|
|
|
private static readonly HashSet<string> _documentTypeSet = [
|
|
GuestConsts.DocumentType_DNI,
|
|
GuestConsts.DocumentType_NIE,
|
|
GuestConsts.DocumentType_PASSPORT,
|
|
"ID",
|
|
"OTHER",
|
|
];
|
|
|
|
private static readonly HashSet<string> _genderOptionSet = [
|
|
"M",
|
|
"F",
|
|
"O",
|
|
];
|
|
|
|
private static readonly HashSet<string> _countryCodeSet = [
|
|
"ABW","AFG","AGO","AIA","ALA","ALB","AND","ARE","ARG","ARM",
|
|
"ASM","ATA","ATF","ATG","AUS","AUT","AZE","BDI","BEL","BEN",
|
|
"BES","BFA","BGD","BGR","BHR","BHS","BIH","BLM","BLR","BLZ",
|
|
"BMU","BOL","BRA","BRB","BRN","BTN","BVT","BWA","CAF","CAN",
|
|
"CCK","CHE","CHL","CHN","CIV","CMR","COD","COG","COK","COL",
|
|
"COM","CPV","CRI","CUB","CUW","CXR","CYM","CYP","CZE","DEU",
|
|
"DJI","DMA","DNK","DOM","DZA","ECU","EGY","ERI","ESH","ESP",
|
|
"EST","ETH","FIN","FJI","FLK","FRA","FRO","FSM","GAB","GBR",
|
|
"GEO","GGY","GHA","GIB","GIN","GLP","GMB","GNB","GNQ","GRC",
|
|
"GRD","GRL","GTM","GUF","GUM","GUY","HKG","HMD","HND","HRV",
|
|
"HTI","HUN","IDN","IMN","IND","IOT","IRL","IRN","IRQ","ISL",
|
|
"ISR","ITA","JAM","JEY","JOR","JPN","KAZ","KEN","KGZ","KHM",
|
|
"KIR","KNA","KOR","KWT","LAO","LBN","LBR","LBY","LCA","LIE",
|
|
"LKA","LSO","LTU","LUX","LVA","MAC","MAF","MAR","MCO","MDA",
|
|
"MDG","MDV","MEX","MHL","MKD","MLI","MLT","MMR","MNE","MNG",
|
|
"MNP","MOZ","MRT","MSR","MTQ","MUS","MWI","MYS","MYT","NAM",
|
|
"NCL","NER","NFK","NGA","NIC","NIU","NLD","NOR","NPL","NRU",
|
|
"NZL","OMN","PAK","PAN","PCN","PER","PHL","PLW","PNG","POL",
|
|
"PRI","PRK","PRT","PRY","PSE","PYF","QAT","REU","ROU","RUS",
|
|
"RWA","SAU","SDN","SEN","SGP","SGS","SHN","SJM","SLB","SLE",
|
|
"SLV","SMR","SOM","SPM","SRB","SSD","STP","SUR","SVK","SVN",
|
|
"SWE","SWZ","SXM","SYC","SYR","TCA","TCD","TGO","THA","TJK",
|
|
"TKL","TKM","TLS","TON","TTO","TUN","TUR","TUV","TWN","TZA",
|
|
"UGA","UKR","UMI","URY","USA","UZB","VAT","VCT","VEN","VGB",
|
|
"VIR","VNM","VUT","WLF","WSM","YEM","ZAF","ZMB","ZWE",
|
|
];
|
|
|
|
#endregion
|
|
|
|
} |