SHA256
- Added DocumentNumber validations. - Added new page to see GuestDocument details.
179 lines
6.0 KiB
Plaintext
179 lines
6.0 KiB
Plaintext
@attribute [Route($"{GuestConsts.Page_GuestDocs_New}")]
|
|
|
|
@using Somnia.GuestLog.Models.DTOs;
|
|
@using Somnia.GuestLog.Services;
|
|
@using Somnia.GuestLog.Validators;
|
|
|
|
@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>
|
|
|
|
<MudStack Row="true" Class="my-4">
|
|
<MudText Typo="Typo.h4" GutterBottom="true">New Guest Document</MudText>
|
|
<MudSpacer />
|
|
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
|
OnClick="() => BtnSaveNewGuest()">
|
|
@LanguageLocale.general_btnCreate
|
|
</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
|
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
|
|
@LanguageLocale.general_btnReturn
|
|
</MudButton>
|
|
</MudStack>
|
|
|
|
@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);
|
|
}
|
|
|
|
private async Task BtnSaveNewGuest()
|
|
{
|
|
bool isFormValid = await _form.ValidateForm();
|
|
if (!isFormValid)
|
|
{
|
|
Snackbar.Add("Invalid Form!", Severity.Error);
|
|
return;
|
|
}
|
|
|
|
GuestDocumentDTO model = _form.Model;
|
|
|
|
Snackbar.Add($"Document '{model.DocumentNum}' creating...", Severity.Info);
|
|
|
|
//Show Loading dialog...
|
|
var loadingDialog = await DialogService.ShowAsync<LoadingDialog>();
|
|
|
|
bool isCreated = await guestDocService.CreateDocumentAsync(model);
|
|
if (!isCreated)
|
|
{
|
|
Snackbar.Add($"Error creating Document '{model.DocumentNum}'", Severity.Error);
|
|
loadingDialog.Close();
|
|
return;
|
|
}
|
|
|
|
Snackbar.Add($"Document '{model.DocumentNum}' Created!", Severity.Success);
|
|
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
|
|
}
|