SHA256
- Added DocumentNumber validations. - Added new page to see GuestDocument details.
181 lines
9.6 KiB
Plaintext
181 lines
9.6 KiB
Plaintext
@using System.Linq;
|
|
@using FluentValidation;
|
|
@using Somnia.GuestLog.Models.DTOs;
|
|
@using Somnia.GuestLog.Services;
|
|
@using Somnia.GuestLog.Validators;
|
|
|
|
@inject IDataListService dataListService;
|
|
@inject IValidator<GuestDocumentDTO> guestDocValidator;
|
|
|
|
|
|
<MudForm @ref="@_form" Model="@Model" Validation="@((guestDocValidator as GuestDocumentDTOValidator)!.ValidateValue)" ValidationDelay="0"
|
|
ReadOnly="@ReadOnly">
|
|
<MudGrid>
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Class="pa-4" Elevation="3" Height="100%">
|
|
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionDocument</MudText>
|
|
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
|
<MudStack Row style="@FieldMarginY">
|
|
<MudSelect @bind-Value="Model.DocumentType" For="@(() => Model.DocumentType)" Label="@LanguageLocale.dto_GuestDocument_DocumentType"
|
|
Required ReadOnly="true">
|
|
@foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes))
|
|
{
|
|
<MudSelectItem Value="docType">@dataListService.GetLocalizedValue(GuestConsts.DataList_DocumentTypes, docType)</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
<MudTextField @bind-Value="Model.DocumentNum" For="@(() => Model.DocumentNum)" Label="@LanguageLocale.dto_GuestDocument_DocumentNum"
|
|
Immediate="true" Required ReadOnly="true" />
|
|
</MudStack>
|
|
|
|
<MudStack Row style="@FieldMarginY">
|
|
<MudDatePicker @bind-Date="Model.IssueDate" For="@(() => Model.IssueDate)" Label="@LanguageLocale.dto_GuestDocument_IssueDate"
|
|
Clearable OpenTo="OpenTo.Year" Editable />
|
|
|
|
<MudTextField @bind-Value="Model.SupportNum" For="@(() => Model.SupportNum)" Label="@LanguageLocale.dto_GuestDocument_SupportNum"
|
|
Immediate="true" Required="@isSuportNumberRequired" Mask="@(new PatternMask("aaa000000"))"
|
|
OnBlur="@(() => Model.SupportNum = Model.SupportNum?.ToUpper())" />
|
|
</MudStack>
|
|
|
|
<MudAutocomplete T="string" @bind-Value="Model.Nationality" For="@(() => Model.Nationality)" Label="@LanguageLocale.dto_GuestDocument_Nationality"
|
|
SearchFunc="@SearchCountryCodes" ToStringFunc="@(e=> string.IsNullOrEmpty(e) ? "" : @dataListService.GetLocalizedValue(GuestConsts.DataList_CountryCodes, e))"
|
|
SelectValueOnTab="true" AdornmentIcon="@Icons.Material.Filled.Search"
|
|
style="@FieldMarginY" />
|
|
</MudPaper>
|
|
</MudItem>
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Class="pa-4" Elevation="3" Height="100%">
|
|
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionGuest</MudText>
|
|
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
|
|
|
<MudTextField @bind-Value="Model.Name" For="@(() => Model.Name)"
|
|
Label="@LanguageLocale.dto_GuestDocument_Name"
|
|
Immediate="true" OnBlur="@(() => Model.Name = Model.Name?.ToUpper())" />
|
|
<MudTextField @bind-Value="Model.Surname" For="@(() => Model.Surname)"
|
|
Label="@LanguageLocale.dto_GuestDocument_Surname"
|
|
Immediate="true" OnBlur="@(() => Model.Surname = Model.Surname?.ToUpper())" />
|
|
<MudTextField @bind-Value="Model.Surname2" For="@(() => Model.Surname2)"
|
|
Label="@LanguageLocale.dto_GuestDocument_Surname2"
|
|
Immediate="true" OnBlur="@(() => Model.Surname2 = Model.Surname2?.ToUpper())" />
|
|
|
|
<MudStack Row style="@FieldMarginY">
|
|
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="@LanguageLocale.dto_GuestDocument_BirthDate"
|
|
Clearable OpenTo="OpenTo.Year" Editable />
|
|
|
|
<MudSelect @bind-Value="Model.Gender" For="@(() => Model.Gender)" Label="@LanguageLocale.dto_GuestDocument_Gender">
|
|
@foreach (string gender in dataListService.GetDataListByName(GuestConsts.DataList_GenderOptions))
|
|
{
|
|
<MudSelectItem Value="gender">@dataListService.GetLocalizedValue(GuestConsts.DataList_GenderOptions, gender)</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
</MudStack>
|
|
</MudPaper>
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Class="pa-4" Elevation="3" Height="100%">
|
|
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionContact</MudText>
|
|
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
|
|
|
<MudStack Row>
|
|
<MudTextField @bind-Value="Model.PhoneNumber" For="@(() => Model.PhoneNumber)"
|
|
Label="@LanguageLocale.dto_GuestDocument_PhoneNumber"
|
|
InputType="InputType.Telephone" Immediate="true" />
|
|
<MudTextField @bind-Value="Model.EmailAddress" For="@(() => Model.EmailAddress)"
|
|
Label="@LanguageLocale.dto_GuestDocument_EmailAddress"
|
|
InputType="InputType.Email" Immediate="true" />
|
|
</MudStack>
|
|
</MudPaper>
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Class="pa-4" Elevation="3" Height="100%">
|
|
<MudText Typo="Typo.subtitle1" Align="Align.Center">@LanguageLocale.control_GuestDocForm_sectionAddress</MudText>
|
|
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
|
|
|
<MudTextField @bind-Value="Model.Address" For="@(() => Model.Address)" Immediate="true" Label="@LanguageLocale.dto_GuestDocument_Address" />
|
|
<MudStack Row style="@FieldMarginY">
|
|
<MudTextField @bind-Value="Model.AddressCity" For="@(() => Model.AddressCity)"
|
|
Label="@LanguageLocale.dto_GuestDocument_AddressCity" Immediate="true" />
|
|
<MudTextField @bind-Value="Model.AddressProvince" For="@(() => Model.AddressProvince)"
|
|
Label="@LanguageLocale.dto_GuestDocument_AddressProvince" Immediate="true" />
|
|
<MudTextField @bind-Value="Model.AddressState" For="@(() => Model.AddressState)"
|
|
Label="@LanguageLocale.dto_GuestDocument_AddressState" Immediate="true" />
|
|
</MudStack>
|
|
<MudStack Row style="@FieldMarginY">
|
|
<MudAutocomplete T="string" @bind-Value="Model.AddressCountry" For="@(() => Model.AddressCountry)"
|
|
Label="@LanguageLocale.dto_GuestDocument_AddressCountry"
|
|
SearchFunc="@SearchCountryCodes" ToStringFunc="@(e=> string.IsNullOrEmpty(e) ? "" : @dataListService.GetLocalizedValue(GuestConsts.DataList_CountryCodes, e))"
|
|
SelectValueOnTab="true" AdornmentIcon="@Icons.Material.Filled.Search" />
|
|
|
|
<MudTextField @bind-Value="Model.ZipCode" For="@(() => Model.ZipCode)" Immediate="true"
|
|
Label="@LanguageLocale.dto_GuestDocument_ZipCode" />
|
|
</MudStack>
|
|
</MudPaper>
|
|
</MudItem>
|
|
</MudGrid>
|
|
<MudText Class="mt-4">@CreateTimeString</MudText>
|
|
</MudForm>
|
|
|
|
@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<string, string>? countryDict = null;
|
|
|
|
private bool isSuportNumberRequired { get => Model?.Nationality == GuestConsts.CountryCode_ESP; }
|
|
private string CreateTimeString
|
|
{
|
|
get
|
|
{
|
|
List<string> 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<bool> ValidateForm()
|
|
{
|
|
await _form.ValidateAsync();
|
|
return _form.IsValid;
|
|
}
|
|
|
|
private async Task<IEnumerable<string>> 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);
|
|
}
|
|
|
|
} |