@using System.Linq; @using FluentValidation; @using Somnia.GuestLog.Models.DTOs; @using Somnia.GuestLog.Services; @using Somnia.GuestLog.Validators; @inject IDataListService dataListService; @inject IValidator guestDocValidator; @LanguageLocale.control_GuestDocForm_sectionDocument @foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes)) { @dataListService.GetLocalizedValue(GuestConsts.DataList_DocumentTypes, docType) } @LanguageLocale.control_GuestDocForm_sectionGuest @foreach (string gender in dataListService.GetDataListByName(GuestConsts.DataList_GenderOptions)) { @dataListService.GetLocalizedValue(GuestConsts.DataList_GenderOptions, gender) } @LanguageLocale.control_GuestDocForm_sectionContact @LanguageLocale.control_GuestDocForm_sectionAddress @CreateTimeString @code { [Parameter] public GuestDocumentDTO Model { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; private MudForm _form = null!; private const string FieldMarginY = "margin-block: 0.5em"; private Dictionary? countryDict = null; private bool isSuportNumberRequired { get => Model?.Nationality == GuestConsts.CountryCode_ESP; } private string CreateTimeString { get { List textList = []; if (Model.CreateTime != null) { textList.Add($"Created at: {Model.CreateTime.Value.ToString()}"); } if (Model.UpdateTime != null) { textList.Add($"Last Update Time: {Model.UpdateTime.Value.ToString()}"); } return string.Join("; ", textList); } } public async Task ValidateForm() { await _form.ValidateAsync(); return _form.IsValid; } private async Task> SearchCountryCodes(string value, CancellationToken token) { // if text is null or empty, show complete list if (string.IsNullOrEmpty(value)) { return new string[0]; } if (countryDict is null || countryDict.Count == 0) { var countryCodeSet = dataListService.GetDataListByName(GuestConsts.DataList_CountryCodes); countryDict = new(countryCodeSet.Count); //Init dict. foreach(string code in dataListService.GetDataListByName(GuestConsts.DataList_CountryCodes)) { countryDict.Add(code, dataListService.GetLocalizedValue(GuestConsts.DataList_CountryCodes, code)); } } return countryDict .Where(x => x.Value.Contains(value, StringComparison.InvariantCultureIgnoreCase)) .Select(x => x.Key); } }