SHA256
GuestLog - Improvements to GuestDocument creation
- Added DocumentNumber validations. - Added new page to see GuestDocument details.
This commit is contained in:
@@ -15,29 +15,31 @@
|
||||
<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>
|
||||
<MudStack Row style="@FieldMarginY">
|
||||
<MudSelect @bind-Value="Model.DocumentType" For="@(() => Model.DocumentType)" Label="@LanguageLocale.dto_GuestDocument_DocumentType"
|
||||
Required>
|
||||
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 />
|
||||
Immediate="true" Required ReadOnly="true" />
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row>
|
||||
<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" />
|
||||
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" />
|
||||
SelectValueOnTab="true" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
style="@FieldMarginY" />
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
@@ -45,13 +47,17 @@
|
||||
<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)" Immediate="true" Label="@LanguageLocale.dto_GuestDocument_Name" />
|
||||
<MudTextField @bind-Value="Model.Surname" For="@(() => Model.Surname)" Immediate="true"
|
||||
Label="@LanguageLocale.dto_GuestDocument_Surname" />
|
||||
<MudTextField @bind-Value="Model.Surname2" For="@(() => Model.Surname2)" Immediate="true"
|
||||
Label="Surname2" />
|
||||
<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>
|
||||
<MudStack Row style="@FieldMarginY">
|
||||
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="@LanguageLocale.dto_GuestDocument_BirthDate"
|
||||
Clearable OpenTo="OpenTo.Year" Editable />
|
||||
|
||||
@@ -71,10 +77,12 @@
|
||||
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
||||
|
||||
<MudStack Row>
|
||||
<MudTextField @bind-Value="Model.PhoneNumber" For="@(() => Model.PhoneNumber)" Immediate="true"
|
||||
Label="@LanguageLocale.dto_GuestDocument_PhoneNumber" />
|
||||
<MudTextField @bind-Value="Model.EmailAddress" For="@(() => Model.EmailAddress)" Immediate="true"
|
||||
Label="@LanguageLocale.dto_GuestDocument_EmailAddress" />
|
||||
<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>
|
||||
@@ -85,16 +93,17 @@
|
||||
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="Model.Address" For="@(() => Model.Address)" Immediate="true" Label="@LanguageLocale.dto_GuestDocument_Address" />
|
||||
<MudStack Row>
|
||||
<MudTextField @bind-Value="Model.AddressCity" For="@(() => Model.AddressCity)" Immediate="true"
|
||||
Label="@LanguageLocale.dto_GuestDocument_AddressCity" />
|
||||
<MudTextField @bind-Value="Model.AddressProvince" For="@(() => Model.AddressProvince)" Immediate="true"
|
||||
Label="@LanguageLocale.dto_GuestDocument_AddressProvince" />
|
||||
<MudTextField @bind-Value="Model.AddressState" For="@(() => Model.AddressState)" Immediate="true"
|
||||
Label="@LanguageLocale.dto_GuestDocument_AddressState" />
|
||||
<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>
|
||||
<MudAutocomplete T="string" @bind-Value="Model.AddressCountry" For="@(() => Model.AddressCountry)" Label="@LanguageLocale.dto_GuestDocument_AddressCountry"
|
||||
<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" />
|
||||
|
||||
@@ -117,9 +126,10 @@
|
||||
|
||||
|
||||
private MudForm _form = null!;
|
||||
private const string FieldMarginY = "margin-block: 0.5em";
|
||||
private Dictionary<string, string>? countryDict = null;
|
||||
|
||||
private bool isSuportNumberRequired { get => Model?.Nationality == "ESP"; }
|
||||
private bool isSuportNumberRequired { get => Model?.Nationality == GuestConsts.CountryCode_ESP; }
|
||||
private string CreateTimeString
|
||||
{
|
||||
get
|
||||
@@ -146,11 +156,13 @@
|
||||
private async Task<IEnumerable<string>> SearchCountryCodes(string value, CancellationToken token)
|
||||
{
|
||||
// if text is null or empty, show complete list
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
if(countryDict is null || countryDict.Count == 0) {
|
||||
if (countryDict is null || countryDict.Count == 0)
|
||||
{
|
||||
var countryCodeSet = dataListService.GetDataListByName(GuestConsts.DataList_CountryCodes);
|
||||
countryDict = new(countryCodeSet.Count);
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
@attribute [Route($"{GuestConsts.Page_GuestDocs_Detail}")]
|
||||
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Services;
|
||||
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentService guestDocService
|
||||
|
||||
|
||||
@inject FluentValidation.IValidator<GuestDocIdDTO> docIdValidator;
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - Details</PageTitle>
|
||||
|
||||
<MudStack Row="true" Class="my-4">
|
||||
<MudText Typo="Typo.h4" GutterBottom="true">Guest Document - "@docId"</MudText>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
||||
OnClick="() => BtnEdit()">
|
||||
@LanguageLocale.general_btnEdit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
|
||||
@LanguageLocale.general_btnReturn
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@if (documentModel is not null)
|
||||
{
|
||||
<GuestDocForm @ref="_form" Model="documentModel" ReadOnly="true" />
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string? docId { get; set; }
|
||||
|
||||
GuestDocForm _form = null!;
|
||||
|
||||
GuestDocumentDTO? documentModel = null;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (docId is null)
|
||||
{
|
||||
Snackbar.Add("No GuestDocument provided!!", Severity.Error);
|
||||
Navigation.NotFound();
|
||||
return;
|
||||
}
|
||||
|
||||
GuestDocIdDTO? docIdModel = GuestDocIdDTO.DecodeFromString(docId);
|
||||
if (docIdModel is null)
|
||||
{
|
||||
Snackbar.Add($"Provided GuestDocId can't be decoded: '{docId}'", Severity.Error);
|
||||
Navigation.NotFound();
|
||||
return;
|
||||
}
|
||||
|
||||
//Get model from db.
|
||||
documentModel = await guestDocService.GetDtoByIdAsync(docIdModel.DocumentType, docIdModel.DocumentNum);
|
||||
if (documentModel is null)
|
||||
{
|
||||
Snackbar.Add($"GuestDocument not found with ID: '{docId}'", Severity.Error);
|
||||
Navigation.NotFound();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnEdit()
|
||||
{
|
||||
Snackbar.Add("Not implemented yet!", Severity.Info);
|
||||
}
|
||||
|
||||
private void BtnReturn()
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
@attribute [Route($"{GuestConsts.Page_GuestDocs_New}")]
|
||||
|
||||
@using Microsoft.EntityFrameworkCore;
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Infrastructure;
|
||||
@using Somnia.GuestLog.Services;
|
||||
@using Somnia.GuestLog.Validators;
|
||||
|
||||
@inject IDbContextFactory<GuestLogContext> contextFactory
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentService guestDocService
|
||||
@inject IDataListService dataListService;
|
||||
|
||||
@inject FluentValidation.IValidator<GuestDocIdDTO> docIdValidator;
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - New</PageTitle>
|
||||
@@ -26,16 +27,98 @@
|
||||
@LanguageLocale.general_btnReturn
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
<GuestDocForm @ref="_form" />
|
||||
|
||||
@if (currentPageMode == ePageMode.selectDocId || currentPageMode == ePageMode.alreadyExistDoc)
|
||||
{
|
||||
<MudPaper Class="pa-4" Elevation="3" Height="100%" Style="">
|
||||
<MudForm @ref="_docIdForm" Model="@currentDocId"
|
||||
Validation="@((docIdValidator as GuestDocIdDTOValidator)!.ValidateValue)">
|
||||
<MudStack Breakpoint="Breakpoint.Sm">
|
||||
<MudSelect @bind-Value="currentDocId.DocumentType" For="@(() => currentDocId.DocumentType)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_DocumentType" Immediate="true" Required>
|
||||
|
||||
@foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes))
|
||||
{
|
||||
<MudSelectItem Value="docType">
|
||||
@dataListService.GetLocalizedValue(GuestConsts.DataList_DocumentTypes, docType)
|
||||
</MudSelectItem>
|
||||
}
|
||||
|
||||
</MudSelect>
|
||||
<MudTextField @bind-Value="currentDocId.DocumentNum" For="@(() => currentDocId.DocumentNum)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_DocumentNum" Required
|
||||
OnBlur="@(() => currentDocId.DocumentNum = currentDocId.DocumentNum.ToUpper())" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.Search" OnClick="() => BtnCheckDocId()" Disabled="@loadingDocId">
|
||||
@LanguageLocale.general_btnSearch
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudForm>
|
||||
|
||||
@if (currentPageMode == ePageMode.alreadyExistDoc)
|
||||
{
|
||||
<MudStack>
|
||||
<MudDivider Class="my-4" />
|
||||
<MudText Typo="Typo.body1" Style="text-align: center;">@LanguageLocale.page_GuestDocNew_msgAlreadyExists
|
||||
</MudText>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.Search" OnClick="() => BtnGoToDocument()">
|
||||
@LanguageLocale.page_GuestDocNew_btnGoExistingDoc
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
}
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
@if (currentPageMode == ePageMode.createNew)
|
||||
{
|
||||
<GuestDocForm @ref="_form" Model="newDocumentModel" />
|
||||
}
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
GuestDocForm _form = null!;
|
||||
MudForm _docIdForm = null!;
|
||||
|
||||
ePageMode currentPageMode = ePageMode.selectDocId;
|
||||
GuestDocIdDTO currentDocId = new() { DocumentNum = "", DocumentType = "" };
|
||||
GuestDocumentDTO newDocumentModel = new();
|
||||
|
||||
bool loadingDocId = false;
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Check if given Document already exists or can be created.
|
||||
/// </summary>
|
||||
private async Task BtnCheckDocId()
|
||||
{
|
||||
await _docIdForm.ValidateAsync();
|
||||
if (!_docIdForm.IsValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
loadingDocId = true;
|
||||
GuestDocumentDTO? dto = await guestDocService.GetDtoByIdAsync(currentDocId.DocumentType, currentDocId.DocumentNum);
|
||||
loadingDocId = false;
|
||||
|
||||
if (dto is null)
|
||||
{
|
||||
//Document don't exist -> Create it.
|
||||
currentPageMode = ePageMode.createNew;
|
||||
|
||||
//Update model with current DocId
|
||||
newDocumentModel.DocumentType = currentDocId.DocumentType;
|
||||
newDocumentModel.DocumentNum = currentDocId.DocumentNum;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//GuestDoc already exists!
|
||||
currentPageMode = ePageMode.alreadyExistDoc;
|
||||
}
|
||||
|
||||
private void BtnReturn()
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
@@ -69,6 +152,27 @@
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
|
||||
private void BtnGoToDocument()
|
||||
{
|
||||
if (currentPageMode != ePageMode.alreadyExistDoc)
|
||||
{
|
||||
Snackbar.Add("Invalid operation!", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
string docId = GuestDocIdDTO.EncodeAsString(currentDocId);
|
||||
string uri = GuestConsts.Page_GuestDocs_Detail.Replace("{docId}", docId);
|
||||
Navigation.NavigateTo(uri);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Models
|
||||
|
||||
enum ePageMode
|
||||
{
|
||||
selectDocId, alreadyExistDoc, createNew
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user