SHA256
GuestLog - StayEntry - Initial Implementation
- Added new entity "StayEntry" to log stays of guests. - Added pages for StayEntry management (List and creation). - New DataList for PaymentMethods. - Other general changes and improvements.
This commit is contained in:
@@ -0,0 +1,117 @@
|
|||||||
|
@using Somnia.GuestLog.Models.DTOs;
|
||||||
|
@using Somnia.GuestLog.Services
|
||||||
|
|
||||||
|
@inject ILogger<AddressQueryDialog> logger;
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IGuestDocumentService guestDocumentService;
|
||||||
|
|
||||||
|
|
||||||
|
<MudDialog Style="max-height: 90%;">
|
||||||
|
<TitleContent>
|
||||||
|
<MudText Typo="Typo.h6">
|
||||||
|
<MudIcon Icon="@Icons.Material.Filled.PersonSearch" Class="mr-3 mb-n1" />
|
||||||
|
@LanguageLocale.control_GuestDocumentSearchDialog_dialogTitle
|
||||||
|
</MudText>
|
||||||
|
</TitleContent>
|
||||||
|
<DialogContent>
|
||||||
|
<GuestDocumentFilterForm @bind-Filter="@filter" />
|
||||||
|
<MudButton StartIcon="@Icons.Material.Filled.Search" OnClick="BtnSearchGuestDocuments" FullWidth
|
||||||
|
Variant="Variant.Filled" Disabled="@isLoading">
|
||||||
|
@LanguageLocale.general_btnSearch
|
||||||
|
</MudButton>
|
||||||
|
<MudDivider DividerType="DividerType.FullWidth" Class="my-4" />
|
||||||
|
|
||||||
|
<MudPaper Class="pa-2" MinHeight="120px">
|
||||||
|
@if (!isLoading && results.Count() == 0)
|
||||||
|
{
|
||||||
|
<MudText Typo="Typo.body1" Align="Align.Center">@LanguageLocale.general_noResults</MudText>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (isLoading)
|
||||||
|
{
|
||||||
|
<MudSkeleton SkeletonType="SkeletonType.Rectangle" Height="100px" />
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!isLoading)
|
||||||
|
{
|
||||||
|
<MudList T="GuestDocumentDTO" @bind-SelectedValue="SelectedResult"
|
||||||
|
SelectionMode="SelectionMode.SingleSelection" Color="Color.Info">
|
||||||
|
@foreach (GuestDocumentDTO result in results)
|
||||||
|
{
|
||||||
|
<MudListItem Value="result">
|
||||||
|
<ChildContent>
|
||||||
|
<MudTextField Value="@($"{result.DocumentType} - {result.DocumentNum}")"
|
||||||
|
Label="@LanguageLocale.dto_GuestDocument_DocumentNum" ReadOnly />
|
||||||
|
<MudTextField Value="@($"{result.Name} {result.Surname} {result.Surname2}")"
|
||||||
|
Label="@LanguageLocale.dto_GuestDocument_Name" ReadOnly />
|
||||||
|
</ChildContent>
|
||||||
|
</MudListItem>
|
||||||
|
}
|
||||||
|
</MudList>
|
||||||
|
}
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudButton OnClick="Cancel">
|
||||||
|
@LanguageLocale.general_btnCancel
|
||||||
|
</MudButton>
|
||||||
|
<MudButton Color="Color.Primary" OnClick="btnSelectGuest">
|
||||||
|
@LanguageLocale.control_GuestDocumentSearchDialog_btnSelectDocument
|
||||||
|
</MudButton>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
// Dialog Instance injected when open by the DialogService.
|
||||||
|
// This field is null when dialog is not open by the DialogService.
|
||||||
|
[CascadingParameter]
|
||||||
|
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||||
|
|
||||||
|
|
||||||
|
private GuestDocFilterDTO filter { get; set; } = new();
|
||||||
|
private IEnumerable<GuestDocumentDTO> results = [];
|
||||||
|
private GuestDocumentDTO? SelectedResult { get; set; }
|
||||||
|
|
||||||
|
private bool isLoading = false;
|
||||||
|
|
||||||
|
|
||||||
|
private void Cancel() => MudDialog.Cancel();
|
||||||
|
|
||||||
|
private async Task BtnSearchGuestDocuments()
|
||||||
|
{
|
||||||
|
if (filter.IsEmpty)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Add some search!", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
isLoading = true;
|
||||||
|
results = await guestDocumentService.GetDtoListByFilterAsync(filter);
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "GuestDocument Search returned an error!");
|
||||||
|
Snackbar.Add($"Error searching: {ex.Message}", Severity.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task btnSelectGuest()
|
||||||
|
{
|
||||||
|
if (SelectedResult is null)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Select a guest document", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogResult dialogResult = DialogResult.Ok<GuestDocumentDTO?>(SelectedResult);
|
||||||
|
|
||||||
|
//Close the dialog when opened by DialogService.
|
||||||
|
logger.LogDebug("GuestDocumentSearchDialog - Closed MudDialogInstance!");
|
||||||
|
MudDialog.Close(dialogResult);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
@using Somnia.GuestLog.Models.DTOs
|
||||||
|
@using Somnia.GuestLog.Services
|
||||||
|
|
||||||
|
@inject IDataListService dataListService;
|
||||||
|
|
||||||
|
<MudForm Model="@Filter" IsTouchedChanged="@(() => FilterChanged.InvokeAsync(Filter))">
|
||||||
|
<MudStack Row Breakpoint="Breakpoint.LgAndDown" StretchItems="StretchItems.All">
|
||||||
|
<MudStack Row style="margin-block: 0.2em;">
|
||||||
|
<MudSelect @bind-Value="Filter.DocumentType" For="@(() => Filter.DocumentType)"
|
||||||
|
Label="@LanguageLocale.dto_GuestDocument_DocumentType" FullWidth Clearable>
|
||||||
|
@foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes))
|
||||||
|
{
|
||||||
|
<MudSelectItem Value="docType">
|
||||||
|
@dataListService.GetLocalizedValue(GuestConsts.DataList_DocumentTypes, docType)
|
||||||
|
</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
<MudTextField @bind-Value="Filter.DocumentNumber" For="@(() => Filter.DocumentNumber)"
|
||||||
|
Label="@LanguageLocale.dto_GuestDocument_DocumentNum" FullWidth Clearable />
|
||||||
|
</MudStack>
|
||||||
|
<MudStack Row style="margin-block: 0.2em;">
|
||||||
|
<MudTextField @bind-Value="Filter.Name" For="@(() => Filter.Name)"
|
||||||
|
Label="@LanguageLocale.dto_GuestDocument_Name" HelperText="@LanguageLocale.general_wildcardHelperText"
|
||||||
|
HelperTextOnFocus="true" FullWidth Clearable OnBlur="@(() => Filter.Name = Filter.Name?.ToUpper())" />
|
||||||
|
<MudTextField @bind-Value="Filter.Surname" For="@(() => Filter.Surname)"
|
||||||
|
Label="@LanguageLocale.dto_GuestDocument_Surname"
|
||||||
|
HelperText="@LanguageLocale.general_wildcardHelperText" HelperTextOnFocus="true" FullWidth Clearable
|
||||||
|
OnBlur="@(() => Filter.Surname = Filter.Surname?.ToUpper())" />
|
||||||
|
</MudStack>
|
||||||
|
</MudStack>
|
||||||
|
</MudForm>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public GuestDocFilterDTO Filter { get; set; } = new();
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<GuestDocFilterDTO> FilterChanged { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
@using FluentValidation;
|
||||||
|
@using Microsoft.AspNetCore.SignalR
|
||||||
|
@using Somnia.GuestLog.Models.DTOs;
|
||||||
|
@using Somnia.GuestLog.Services;
|
||||||
|
@using Somnia.GuestLog.Validators;
|
||||||
|
|
||||||
|
@inject IDataListService dataListService;
|
||||||
|
@inject IValidator<StayEntryDTO> stayValidator;
|
||||||
|
@inject IDialogService dialogService;
|
||||||
|
@inject ISnackbar snackbar
|
||||||
|
|
||||||
|
|
||||||
|
<MudForm @ref="@_form" Model="@Model" Validation="@((stayValidator as StayEntryDTOValidator)!.ValidateValue)"
|
||||||
|
ReadOnly="@ReadOnly">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" xl=6>
|
||||||
|
<MudPaper Class="pa-4" Elevation="3" Height="100%">
|
||||||
|
<MudText Typo="Typo.subtitle1" Align="Align.Center">
|
||||||
|
@LanguageLocale.control_StayEntryForm_sectionDetails
|
||||||
|
</MudText>
|
||||||
|
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
||||||
|
|
||||||
|
<MudStack Row style="@FieldMarginY">
|
||||||
|
<MudDatePicker @bind-Date="Model.DateIn" For="@(() => Model.DateIn)"
|
||||||
|
Label="@LanguageLocale.dto_StayEntry_DateIn" Clearable OpenTo="OpenTo.Date" Editable />
|
||||||
|
<MudTimePicker @bind-Time="TimeIn" Label=" " Editable />
|
||||||
|
<MudDatePicker @bind-Date="Model.DateOut" For="@(() => Model.DateOut)"
|
||||||
|
Label="@LanguageLocale.dto_StayEntry_DateOut" Clearable OpenTo="OpenTo.Date" Editable />
|
||||||
|
<MudTimePicker @bind-Time="TimeOut" Label=" " Editable />
|
||||||
|
</MudStack>
|
||||||
|
<MudStack Row style="@FieldMarginY">
|
||||||
|
<MudTextField @bind-Value="Model.RoomCount" For="@(() => Model.RoomCount)"
|
||||||
|
Label="@LanguageLocale.dto_StayEntry_RoomCount" InputType="InputType.Number" FullWidth />
|
||||||
|
<MudTextField @bind-Value="Model.RoomNumber" For="@(() => Model.RoomNumber)"
|
||||||
|
Label="@LanguageLocale.dto_StayEntry_RoomNumber" FullWidth />
|
||||||
|
|
||||||
|
<MudSelect @bind-Value="Model.PaymentMethod" For="@(() => Model.PaymentMethod)"
|
||||||
|
Label="@LanguageLocale.dto_StayEntry_PaymentMethod" FullWidth>
|
||||||
|
@foreach (string payment in PaymentMethodSet)
|
||||||
|
{
|
||||||
|
<MudSelectItem Value="payment">
|
||||||
|
@dataListService.GetLocalizedValue(GuestConsts.DataList_PaymentMethods, payment)
|
||||||
|
</MudSelectItem>
|
||||||
|
}
|
||||||
|
</MudSelect>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" xl=6>
|
||||||
|
<MudPaper Class="pa-4" Elevation="3" Height="100%" Width="100%">
|
||||||
|
<MudText Typo="Typo.subtitle1" Align="Align.Center">
|
||||||
|
@LanguageLocale.control_StayEntryForm_sectionGuests
|
||||||
|
</MudText>
|
||||||
|
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
||||||
|
|
||||||
|
@if (!ReadOnly)
|
||||||
|
{
|
||||||
|
<MudStack Row style="@FieldMarginY">
|
||||||
|
<MudButton OnClick="BtnAddGuest" StartIcon="@Icons.Material.Filled.Add">
|
||||||
|
@LanguageLocale.control_StayEntryForm_btnAddGuest
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
}
|
||||||
|
|
||||||
|
<MudTable Items="@Model.GuestDocuments" Hover="true">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>@LanguageLocale.dto_GuestDocument_DocumentType</MudTh>
|
||||||
|
<MudTh>@LanguageLocale.dto_GuestDocument_DocumentNum</MudTh>
|
||||||
|
<MudTh>@LanguageLocale.dto_GuestDocument_Name</MudTh>
|
||||||
|
<MudTh>@LanguageLocale.dto_GuestDocument_Surname</MudTh>
|
||||||
|
<MudTh>@LanguageLocale.dto_GuestDocument_Surname2</MudTh>
|
||||||
|
@if (!ReadOnly)
|
||||||
|
{
|
||||||
|
<MudTh>@LanguageLocale.general_actions</MudTh>
|
||||||
|
}
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_DocumentType">
|
||||||
|
@context.DocumentType
|
||||||
|
</MudTd>
|
||||||
|
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_DocumentNum">
|
||||||
|
@context.DocumentNum
|
||||||
|
</MudTd>
|
||||||
|
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_Name">
|
||||||
|
@context.Name
|
||||||
|
</MudTd>
|
||||||
|
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_Surname" HideSmall="true">
|
||||||
|
@context.Surname
|
||||||
|
</MudTd>
|
||||||
|
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_Surname2" HideSmall="true">
|
||||||
|
@context.Surname2
|
||||||
|
</MudTd>
|
||||||
|
@if (!ReadOnly)
|
||||||
|
{
|
||||||
|
<MudTd DataLabel="@LanguageLocale.general_actions">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||||
|
OnClick="@(() => BtnDeleteGuest(context.DocumentType!, context.DocumentNum!))" />
|
||||||
|
</MudTd>
|
||||||
|
}
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
|
||||||
|
</MudPaper>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudForm>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public StayEntryDTO Model { private get; set; } = new();
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool ReadOnly { get; set; } = false;
|
||||||
|
|
||||||
|
private TimeSpan? TimeIn = DateTime.Now.TimeOfDay;
|
||||||
|
private TimeSpan? TimeOut = new(hours: 12, minutes: 0, seconds: 0);
|
||||||
|
|
||||||
|
|
||||||
|
private MudForm _form = null!;
|
||||||
|
|
||||||
|
private const string FieldMarginY = "margin-block: 0.5em";
|
||||||
|
private IEnumerable<string> PaymentMethodSet
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (field is null)
|
||||||
|
{
|
||||||
|
field = dataListService.GetDataListByName(GuestConsts.DataList_PaymentMethods);
|
||||||
|
}
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
Model.DateIn = DateTime.Today;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<bool> ValidateForm()
|
||||||
|
{
|
||||||
|
await _form.ValidateAsync();
|
||||||
|
|
||||||
|
if (Model.GuestDocuments.Count == 0)
|
||||||
|
{
|
||||||
|
snackbar.Add("At least 1 guest is required!", MudBlazor.Severity.Warning);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _form.IsValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StayEntryDTO GetModel()
|
||||||
|
{
|
||||||
|
//Update model times.
|
||||||
|
Model.DateIn = GetDateTimeFromDateAndTime(Model.DateIn, TimeIn);
|
||||||
|
Model.DateOut = GetDateTimeFromDateAndTime(Model.DateOut, TimeOut);
|
||||||
|
|
||||||
|
return Model;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
private static DateTime? GetDateTimeFromDateAndTime(DateTime? date, TimeSpan? time)
|
||||||
|
{
|
||||||
|
DateOnly? dateOnly = date is not null ? DateOnly.FromDateTime(date.Value) : null;
|
||||||
|
TimeOnly? timeOnly = time is not null ? TimeOnly.FromTimeSpan(time.Value) : null;
|
||||||
|
|
||||||
|
if (dateOnly is not null && timeOnly is not null)
|
||||||
|
{
|
||||||
|
return new DateTime(dateOnly.Value, timeOnly.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Event Handlers
|
||||||
|
|
||||||
|
private async Task BtnAddGuest()
|
||||||
|
{
|
||||||
|
var dialog = await dialogService.ShowAsync<GuestDocumentSearchDialog>();
|
||||||
|
DialogResult? result = await dialog.Result;
|
||||||
|
|
||||||
|
if (result is null || result.Canceled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuestDocumentDTO? resultData = await dialog.GetReturnValueAsync<GuestDocumentDTO>();
|
||||||
|
|
||||||
|
if (resultData is null)
|
||||||
|
{
|
||||||
|
snackbar.Add("Error! No Guest Document selected!", MudBlazor.Severity.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if this guest is already added.
|
||||||
|
bool alreadyAdded = Model.GuestDocuments.Any(e => e.DocumentType == resultData.DocumentType
|
||||||
|
&& e.DocumentNum == resultData.DocumentNum);
|
||||||
|
if (alreadyAdded)
|
||||||
|
{
|
||||||
|
snackbar.Add("GuestDocument already added!", MudBlazor.Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model.GuestDocuments.Add(resultData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnDeleteGuest(string docType, string docNum)
|
||||||
|
{
|
||||||
|
//Filter out given GuestDocument from model.
|
||||||
|
Model.GuestDocuments = Model.GuestDocuments.Where(e => !(e.DocumentType == docType && e.DocumentNum == docNum)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
<MudNavLink Href="weather" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">Weather</MudNavLink>
|
<MudNavLink Href="weather" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">Weather</MudNavLink>
|
||||||
|
|
||||||
<MudNavLink Href="@GuestConsts.Page_GuestDocs_List" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.DocumentScanner">Guests</MudNavLink>
|
<MudNavLink Href="@GuestConsts.Page_GuestDocs_List" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.DocumentScanner">Guests</MudNavLink>
|
||||||
|
<MudNavLink Href="@GuestConsts.Page_StayEntry_List" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Book">Stays</MudNavLink>
|
||||||
</MudNavMenu>
|
</MudNavMenu>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
<ToolBarContent>
|
<ToolBarContent>
|
||||||
<MudText Typo="Typo.subtitle1">@LanguageLocale.page_GuestDocList_documentList</MudText>
|
<MudText Typo="Typo.subtitle1">@LanguageLocale.page_GuestDocList_documentList</MudText>
|
||||||
<MudStack Class="ml-auto" Row="true" AlignItems="AlignItems.Center">
|
<MudStack Class="ml-auto" Row="true" AlignItems="AlignItems.Center">
|
||||||
<MudCheckBox @bind-Value="_showAllData" Label="@LanguageLocale.page_GuestDocList_showAllElements"
|
<MudCheckBox @bind-Value="_showAllData" Label="@LanguageLocale.general_showAllElements"
|
||||||
LabelPlacement="Placement.Start" />
|
LabelPlacement="Placement.Start" />
|
||||||
<MudButton StartIcon="@Icons.Material.Outlined.ViewColumn" Variant="Variant.Outlined" Size="Size.Small"
|
<MudButton StartIcon="@Icons.Material.Outlined.ViewColumn" Variant="Variant.Outlined" Size="Size.Small"
|
||||||
OnClick="(args) => BtnConfigureColumnsClick(args)">
|
OnClick="(args) => BtnConfigureColumnsClick(args)">
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
@attribute [Route($"{GuestConsts.Page_StayEntry_List}")]
|
||||||
|
|
||||||
|
@using Somnia.GuestLog.Models.DTOs;
|
||||||
|
@using Somnia.GuestLog.Services;
|
||||||
|
|
||||||
|
@inject IStayEntryService StayEntryService
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
@inject IDataListService dataListService;
|
||||||
|
|
||||||
|
<PageTitle>Somnia - Stay Entries</PageTitle>
|
||||||
|
|
||||||
|
<MudStack Row="true" Class="my-4">
|
||||||
|
<MudText Typo="Typo.h4" GutterBottom="true">@LanguageLocale.page_StayEntryList_pageTitle</MudText>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
||||||
|
StartIcon="@Icons.Material.Filled.Search" OnClick="() => BtnSearchDataAsync()">
|
||||||
|
@LanguageLocale.general_btnSearch
|
||||||
|
</MudButton>
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
||||||
|
OnClick="() => BtnNewStay()">
|
||||||
|
@LanguageLocale.page_StayEntryList_btnNewStay
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
|
||||||
|
<MudDataGrid @ref="_dataGrid" T="StayEntryDTO" Items="@stayEntryList" Loading="@_dataLoading" ReadOnly="true"
|
||||||
|
Elevation="2">
|
||||||
|
<ToolBarContent>
|
||||||
|
<MudText Typo="Typo.subtitle1">@LanguageLocale.page_StayEntryList_entryList</MudText>
|
||||||
|
<MudStack Class="ml-auto" Row="true" AlignItems="AlignItems.Center">
|
||||||
|
<MudCheckBox @bind-Value="_showAllData" Label="@LanguageLocale.general_showAllElements"
|
||||||
|
LabelPlacement="Placement.Start" />
|
||||||
|
</MudStack>
|
||||||
|
</ToolBarContent>
|
||||||
|
<Columns>
|
||||||
|
<PropertyColumn Property="x => x.Id" Hideable="false" Title="@LanguageLocale.dto_StayEntry_Id" />
|
||||||
|
<PropertyColumn Property="x => x.DateIn" Title="@LanguageLocale.dto_StayEntry_DateIn" />
|
||||||
|
<PropertyColumn Property="x => x.DateOut" Title="@LanguageLocale.dto_StayEntry_DateOut" />
|
||||||
|
<PropertyColumn Property="x => x.RoomNumber" Title="@LanguageLocale.dto_StayEntry_RoomNumber" />
|
||||||
|
<PropertyColumn Title="@LanguageLocale.dto_StayEntry_PaymentMethod"
|
||||||
|
Property="x => dataListService.GetLocalizedValue(GuestConsts.DataList_PaymentMethods, x.PaymentMethod)" />
|
||||||
|
|
||||||
|
<PropertyColumn Property="x => x.UpdateTime" Title="@LanguageLocale.dto_GuestDocument_UpdateTime" />
|
||||||
|
|
||||||
|
@* <TemplateColumn CellClass="d-flex justify-between" Title="Options" StickyRight Hideable="false"
|
||||||
|
ShowColumnOptions="false">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Info"
|
||||||
|
OnClick="() => BtnViewDetails(context.Item)" />
|
||||||
|
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Delete"
|
||||||
|
OnClick="() => BtnDeleteItem(context.Item)" />
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn> *@
|
||||||
|
</Columns>
|
||||||
|
<PagerContent>
|
||||||
|
<MudDataGridPager T="StayEntryDTO" />
|
||||||
|
</PagerContent>
|
||||||
|
</MudDataGrid>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
private bool _dataLoading = true;
|
||||||
|
private bool _showAllData = false;
|
||||||
|
private const int resultLimit = 200;
|
||||||
|
|
||||||
|
private IEnumerable<StayEntryDTO> stayEntryList = [];
|
||||||
|
|
||||||
|
private MudDataGrid<StayEntryDTO> _dataGrid = null!;
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await LoadDataAsync(showMsg: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadDataAsync(bool showMsg = true)
|
||||||
|
{
|
||||||
|
_dataLoading = true;
|
||||||
|
|
||||||
|
int dataLimit = _showAllData ? 0 : resultLimit;
|
||||||
|
stayEntryList = await StayEntryService.GetDtoListAsync();
|
||||||
|
//stayEntryList = await StayEntryService.GetDtoListAsync(filter: filter, limit: dataLimit);
|
||||||
|
|
||||||
|
if (showMsg)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Data loaded from DB", Severity.Info, o => o.VisibleStateDuration = 1000);
|
||||||
|
}
|
||||||
|
_dataLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region Event Handlers
|
||||||
|
|
||||||
|
private async Task BtnSearchDataAsync()
|
||||||
|
{
|
||||||
|
await LoadDataAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnNewStay()
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo(GuestConsts.Page_StayEntry_New);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
@attribute [Route($"{GuestConsts.Page_StayEntry_New}")]
|
||||||
|
|
||||||
|
@using Somnia.GuestLog.Models.DTOs;
|
||||||
|
@using Somnia.GuestLog.Services;
|
||||||
|
|
||||||
|
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject IStayEntryService stayService
|
||||||
|
@inject IDataListService dataListService;
|
||||||
|
|
||||||
|
<PageTitle>Somnia - Stay Entries - New</PageTitle>
|
||||||
|
|
||||||
|
<MudStack Row="true" Class="my-4">
|
||||||
|
<MudText Typo="Typo.h4" GutterBottom="true">
|
||||||
|
@LanguageLocale.page_StayEntryNew_pageTitle
|
||||||
|
</MudText>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
||||||
|
OnClick="() => BtnSaveStay()">
|
||||||
|
@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>
|
||||||
|
|
||||||
|
<StayEntryForm @ref="_form" Model="@newStayModel" />
|
||||||
|
|
||||||
|
@code {
|
||||||
|
StayEntryForm _form = null!;
|
||||||
|
|
||||||
|
StayEntryDTO newStayModel = new();
|
||||||
|
|
||||||
|
|
||||||
|
private void BtnReturn()
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo(GuestConsts.Page_StayEntry_List);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task BtnSaveStay()
|
||||||
|
{
|
||||||
|
bool isFormValid = await _form.ValidateForm();
|
||||||
|
if (!isFormValid)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Invalid Form!", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadingDialog = await DialogService.ShowAsync<LoadingDialog>();
|
||||||
|
|
||||||
|
StayEntryDTO model = _form.GetModel();
|
||||||
|
bool isCreated = await stayService.CreateEntryAsync(model);
|
||||||
|
if (!isCreated)
|
||||||
|
{
|
||||||
|
Snackbar.Add($"Error creating StayEntry", Severity.Error);
|
||||||
|
loadingDialog.Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Snackbar.Add($"StayEntry Created!", Severity.Success);
|
||||||
|
Navigation.NavigateTo(GuestConsts.Page_StayEntry_List);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,4 +12,7 @@
|
|||||||
@using Somnia.GuestLog
|
@using Somnia.GuestLog
|
||||||
@using Somnia.GuestLog.Components
|
@using Somnia.GuestLog.Components
|
||||||
@using Somnia.GuestLog.Components.Layout
|
@using Somnia.GuestLog.Components.Layout
|
||||||
|
@using Somnia.GuestLog.Components.Forms
|
||||||
|
@using Somnia.GuestLog.Components.Controls
|
||||||
@using Somnia.GuestLog.Resources
|
@using Somnia.GuestLog.Resources
|
||||||
|
@using System.Linq;
|
||||||
@@ -7,10 +7,14 @@ public static class GuestConsts
|
|||||||
public const string Page_GuestDocs_New = "/guest-documents/new";
|
public const string Page_GuestDocs_New = "/guest-documents/new";
|
||||||
public const string Page_GuestDocs_Detail = "/guest-documents/d/{docId}";
|
public const string Page_GuestDocs_Detail = "/guest-documents/d/{docId}";
|
||||||
|
|
||||||
|
public const string Page_StayEntry_List = "/stayEntries";
|
||||||
|
public const string Page_StayEntry_New = "/stayEntries/new";
|
||||||
|
|
||||||
|
|
||||||
public const string DataList_DocumentTypes = "DocumentType";
|
public const string DataList_DocumentTypes = "DocumentType";
|
||||||
public const string DataList_GenderOptions = "GenderOption";
|
public const string DataList_GenderOptions = "GenderOption";
|
||||||
public const string DataList_CountryCodes = "CountryCode";
|
public const string DataList_CountryCodes = "CountryCode";
|
||||||
|
public const string DataList_PaymentMethods = "PaymentMethod";
|
||||||
|
|
||||||
|
|
||||||
public const string CountryCode_ESP = "ESP";
|
public const string CountryCode_ESP = "ESP";
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Somnia.GuestLog.Infrastructure;
|
||||||
|
|
||||||
|
public static class DbConsts
|
||||||
|
{
|
||||||
|
public const string DbType_Timestamptz = "timestamp with time zone";
|
||||||
|
public const string DbType_Timestamptz_0 = "timestamp(0) with time zone";
|
||||||
|
public const string DbType_Timestamptz_3 = "timestamp(3) with time zone";
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Somnia.GuestLog.Models.Entities;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Infrastructure.EntityConfigs;
|
||||||
|
|
||||||
|
public class StayEntryEntityConfig : IEntityTypeConfiguration<StayEntry>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<StayEntry> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable("StayEntry");
|
||||||
|
|
||||||
|
//PK
|
||||||
|
builder.HasKey(e => e.Id);
|
||||||
|
|
||||||
|
builder.Property(e => e.Id)
|
||||||
|
.IsRequired()
|
||||||
|
.UseIdentityByDefaultColumn();
|
||||||
|
|
||||||
|
builder.Property(e => e.DateIn)
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType(DbConsts.DbType_Timestamptz_0);
|
||||||
|
builder.Property(e => e.DateOut)
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType(DbConsts.DbType_Timestamptz_0);
|
||||||
|
|
||||||
|
builder.Property(e => e.RoomNumber)
|
||||||
|
.HasMaxLength(32);
|
||||||
|
builder.Property(e => e.PaymentMethod)
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(5);
|
||||||
|
|
||||||
|
|
||||||
|
builder.Property(e => e.CreateTime)
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType(DbConsts.DbType_Timestamptz);
|
||||||
|
builder.Property(e => e.UpdateTime)
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType(DbConsts.DbType_Timestamptz);
|
||||||
|
|
||||||
|
|
||||||
|
builder.HasMany(e => e.GuestDocuments)
|
||||||
|
.WithMany();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,11 +11,13 @@ public partial class GuestLogContext : DbContext
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
public DbSet<GuestDocument> GuestDocuments { get; set; }
|
public DbSet<GuestDocument> GuestDocuments { get; set; }
|
||||||
|
public DbSet<StayEntry> StayEntries { get; set; }
|
||||||
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.ApplyConfiguration<GuestDocument>(new GuestDocumentEntityConfig());
|
modelBuilder.ApplyConfiguration<GuestDocument>(new GuestDocumentEntityConfig());
|
||||||
|
modelBuilder.ApplyConfiguration<StayEntry>(new StayEntryEntityConfig());
|
||||||
|
|
||||||
OnModelCreatingPartial(modelBuilder);
|
OnModelCreatingPartial(modelBuilder);
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|||||||
Generated
+191
@@ -0,0 +1,191 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using Somnia.GuestLog.Infrastructure;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(GuestLogContext))]
|
||||||
|
[Migration("20260813085339_AddTable_StayEntry")]
|
||||||
|
partial class AddTable_StayEntry
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("GuestDocumentStayEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("StayEntryId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("GuestDocumentsDocumentType")
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("GuestDocumentsDocumentNum")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("StayEntryId", "GuestDocumentsDocumentType", "GuestDocumentsDocumentNum");
|
||||||
|
|
||||||
|
b.HasIndex("GuestDocumentsDocumentType", "GuestDocumentsDocumentNum");
|
||||||
|
|
||||||
|
b.ToTable("GuestDocumentStayEntry");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.GuestDocument", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("DocumentType")
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("DocumentNum")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<DateOnly>("BirthDate")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("EmailAddress")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Gender")
|
||||||
|
.HasMaxLength(1)
|
||||||
|
.HasColumnType("character varying(1)");
|
||||||
|
|
||||||
|
b.Property<DateOnly>("IssueDate")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Nationality")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(3)
|
||||||
|
.HasColumnType("character varying(3)");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("SupportNum")
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("character varying(10)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname2")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.ComplexProperty(typeof(Dictionary<string, object>), "AddressDetails", "Somnia.GuestLog.Models.Entities.GuestDocument.AddressDetails#GuestAddress", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("Address")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressCity")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressCountry")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(3)
|
||||||
|
.HasColumnType("character varying(3)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressProvince")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressState")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("ZipCode")
|
||||||
|
.HasMaxLength(12)
|
||||||
|
.HasColumnType("character varying(12)");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasKey("DocumentType", "DocumentNum");
|
||||||
|
|
||||||
|
b.ToTable("GuestDocument", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.StayEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateIn")
|
||||||
|
.HasColumnType("timestamp(0) with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateOut")
|
||||||
|
.HasColumnType("timestamp(0) with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("PaymentMethod")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(5)
|
||||||
|
.HasColumnType("character varying(5)");
|
||||||
|
|
||||||
|
b.Property<int>("RoomCount")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("RoomNumber")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("StayEntry", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GuestDocumentStayEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Somnia.GuestLog.Models.Entities.StayEntry", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("StayEntryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Somnia.GuestLog.Models.Entities.GuestDocument", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("GuestDocumentsDocumentType", "GuestDocumentsDocumentNum")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddTable_StayEntry : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "StayEntry",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
DateIn = table.Column<DateTime>(type: "timestamp(0) with time zone", nullable: false),
|
||||||
|
DateOut = table.Column<DateTime>(type: "timestamp(0) with time zone", nullable: false),
|
||||||
|
RoomCount = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
RoomNumber = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||||
|
PaymentMethod = table.Column<string>(type: "character varying(5)", maxLength: 5, nullable: false),
|
||||||
|
CreateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
UpdateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_StayEntry", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "GuestDocumentStayEntry",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
StayEntryId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
GuestDocumentsDocumentType = table.Column<string>(type: "character varying(8)", nullable: false),
|
||||||
|
GuestDocumentsDocumentNum = table.Column<string>(type: "character varying(64)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_GuestDocumentStayEntry", x => new { x.StayEntryId, x.GuestDocumentsDocumentType, x.GuestDocumentsDocumentNum });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_GuestDocumentStayEntry_GuestDocument_GuestDocumentsDocument~",
|
||||||
|
columns: x => new { x.GuestDocumentsDocumentType, x.GuestDocumentsDocumentNum },
|
||||||
|
principalTable: "GuestDocument",
|
||||||
|
principalColumns: new[] { "DocumentType", "DocumentNum" },
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_GuestDocumentStayEntry_StayEntry_StayEntryId",
|
||||||
|
column: x => x.StayEntryId,
|
||||||
|
principalTable: "StayEntry",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_GuestDocumentStayEntry_GuestDocumentsDocumentType_GuestDocu~",
|
||||||
|
table: "GuestDocumentStayEntry",
|
||||||
|
columns: new[] { "GuestDocumentsDocumentType", "GuestDocumentsDocumentNum" });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "GuestDocumentStayEntry");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "StayEntry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,24 @@ namespace Somnia.GuestLog.Infrastructure.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("GuestDocumentStayEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("StayEntryId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("GuestDocumentsDocumentType")
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("GuestDocumentsDocumentNum")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("StayEntryId", "GuestDocumentsDocumentType", "GuestDocumentsDocumentNum");
|
||||||
|
|
||||||
|
b.HasIndex("GuestDocumentsDocumentType", "GuestDocumentsDocumentNum");
|
||||||
|
|
||||||
|
b.ToTable("GuestDocumentStayEntry");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.GuestDocument", b =>
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.GuestDocument", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("DocumentType")
|
b.Property<string>("DocumentType")
|
||||||
@@ -112,6 +130,58 @@ namespace Somnia.GuestLog.Infrastructure.Migrations
|
|||||||
|
|
||||||
b.ToTable("GuestDocument", (string)null);
|
b.ToTable("GuestDocument", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.StayEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateIn")
|
||||||
|
.HasColumnType("timestamp(0) with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateOut")
|
||||||
|
.HasColumnType("timestamp(0) with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("PaymentMethod")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(5)
|
||||||
|
.HasColumnType("character varying(5)");
|
||||||
|
|
||||||
|
b.Property<int>("RoomCount")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("RoomNumber")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("StayEntry", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GuestDocumentStayEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Somnia.GuestLog.Models.Entities.StayEntry", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("StayEntryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Somnia.GuestLog.Models.Entities.GuestDocument", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("GuestDocumentsDocumentType", "GuestDocumentsDocumentNum")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,11 @@ public class GuestDocFilterDTO
|
|||||||
|
|
||||||
public string? PhoneNumber { get; set; }
|
public string? PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsEmpty => string.IsNullOrEmpty(DocumentType)
|
||||||
|
&& string.IsNullOrEmpty(DocumentNumber)
|
||||||
|
&& string.IsNullOrEmpty(Name)
|
||||||
|
&& string.IsNullOrEmpty(Surname)
|
||||||
|
&& string.IsNullOrEmpty(PhoneNumber);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,7 @@ public class GuestDocumentDTO
|
|||||||
|
|
||||||
public DateTime? CreateTime { get; set; }
|
public DateTime? CreateTime { get; set; }
|
||||||
public DateTime? UpdateTime { get; set; }
|
public DateTime? UpdateTime { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public string FullKey => $"{DocumentType}-{DocumentNum}";
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace Somnia.GuestLog.Models.DTOs;
|
||||||
|
|
||||||
|
public class StayEntryDTO
|
||||||
|
{
|
||||||
|
public long? Id { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateIn { get; set; }
|
||||||
|
public DateTime? DateOut { get; set; }
|
||||||
|
|
||||||
|
public int? RoomCount { get; set; }
|
||||||
|
public string? RoomNumber { get; set; }
|
||||||
|
public string? PaymentMethod { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public List<GuestDocumentDTO> GuestDocuments { get; set; } = [];
|
||||||
|
|
||||||
|
|
||||||
|
public DateTime? CreateTime { get; set; }
|
||||||
|
public DateTime? UpdateTime { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
namespace Somnia.GuestLog.Models.Entities;
|
||||||
|
|
||||||
|
public class StayEntry : BaseEntity
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
public required DateTime DateIn { get; set; }
|
||||||
|
public required DateTime DateOut { get; set; }
|
||||||
|
|
||||||
|
public required int RoomCount { get; set; }
|
||||||
|
public string? RoomNumber { get; set; }
|
||||||
|
|
||||||
|
public required string PaymentMethod { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<GuestDocument> GuestDocuments { get; } = [];
|
||||||
|
|
||||||
|
|
||||||
|
//Generated Properties.
|
||||||
|
public required DateTime CreateTime { get; set; }
|
||||||
|
public required DateTime UpdateTime { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public override string GetFullKey() => $"{Id}";
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using Somnia.GuestLog.Models.DTOs;
|
||||||
|
using Somnia.GuestLog.Models.Entities;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Models;
|
||||||
|
|
||||||
|
internal static class EntityMapping
|
||||||
|
{
|
||||||
|
|
||||||
|
public static GuestDocumentDTO MapGuestDocumentEntityToDTO(GuestDocument entity)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
DocumentType = entity.DocumentType,
|
||||||
|
DocumentNum = entity.DocumentNum,
|
||||||
|
IssueDate = entity.IssueDate.ToDateTime(TimeOnly.MinValue),
|
||||||
|
SupportNum = entity.SupportNum,
|
||||||
|
Nationality = entity.Nationality,
|
||||||
|
Name = entity.Name,
|
||||||
|
Surname = entity.Surname,
|
||||||
|
Surname2 = entity.Surname2,
|
||||||
|
BirthDate = entity.BirthDate.ToDateTime(TimeOnly.MinValue),
|
||||||
|
Gender = entity.Gender,
|
||||||
|
PhoneNumber = entity.PhoneNumber,
|
||||||
|
EmailAddress = entity.EmailAddress,
|
||||||
|
Address = entity.AddressDetails?.Address ?? "",
|
||||||
|
AddressCity = entity.AddressDetails?.AddressCity ?? "",
|
||||||
|
AddressProvince = entity.AddressDetails?.AddressProvince ?? "",
|
||||||
|
AddressState = entity.AddressDetails?.AddressState ?? "",
|
||||||
|
AddressCountry = entity.AddressDetails?.AddressCountry! ?? "",
|
||||||
|
ZipCode = entity.AddressDetails?.ZipCode ?? "",
|
||||||
|
CreateTime = entity.CreateTime,
|
||||||
|
UpdateTime = entity.UpdateTime,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StayEntryDTO MapStayEntryEntityToDTO(StayEntry entity)
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = entity.Id,
|
||||||
|
DateIn = entity.DateIn,
|
||||||
|
DateOut = entity.DateOut,
|
||||||
|
RoomCount = entity.RoomCount,
|
||||||
|
RoomNumber = entity.RoomNumber,
|
||||||
|
PaymentMethod = entity.PaymentMethod,
|
||||||
|
CreateTime = entity.CreateTime,
|
||||||
|
UpdateTime = entity.UpdateTime,
|
||||||
|
GuestDocuments = [.. entity.GuestDocuments.Select(e => MapGuestDocumentEntityToDTO(e))],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,9 +35,11 @@ builder.Services.AddHttpClient();
|
|||||||
// Add Validation Services
|
// Add Validation Services
|
||||||
builder.Services.AddSingleton<IValidator<GuestDocumentDTO>, GuestDocumentDTOValidator>();
|
builder.Services.AddSingleton<IValidator<GuestDocumentDTO>, GuestDocumentDTOValidator>();
|
||||||
builder.Services.AddSingleton<IValidator<GuestDocIdDTO>, GuestDocIdDTOValidator>();
|
builder.Services.AddSingleton<IValidator<GuestDocIdDTO>, GuestDocIdDTOValidator>();
|
||||||
|
builder.Services.AddSingleton<IValidator<StayEntryDTO>, StayEntryDTOValidator>();
|
||||||
|
|
||||||
// Add Services
|
// Add Services
|
||||||
builder.Services.AddSingleton<IGuestDocumentService, GuestDocumentService>();
|
builder.Services.AddSingleton<IGuestDocumentService, GuestDocumentService>();
|
||||||
|
builder.Services.AddSingleton<IStayEntryService, StayEntryService>();
|
||||||
builder.Services.AddSingleton<IDataListService, StaticDataListService>();
|
builder.Services.AddSingleton<IDataListService, StaticDataListService>();
|
||||||
|
|
||||||
// Add Factories (and it's services)
|
// Add Factories (and it's services)
|
||||||
|
|||||||
@@ -388,4 +388,10 @@
|
|||||||
<data name="dataList.GenderOption.F" xml:space="preserve"><value>Female</value></data>
|
<data name="dataList.GenderOption.F" xml:space="preserve"><value>Female</value></data>
|
||||||
<data name="dataList.GenderOption.O" xml:space="preserve"><value>Other</value></data>
|
<data name="dataList.GenderOption.O" xml:space="preserve"><value>Other</value></data>
|
||||||
|
|
||||||
|
<data name="dataList.PaymentMethod.EFECT" xml:space="preserve"><value>Cash</value></data>
|
||||||
|
<data name="dataList.PaymentMethod.TARJT" xml:space="preserve"><value>Card</value></data>
|
||||||
|
<data name="dataList.PaymentMethod.TRANS" xml:space="preserve"><value>Wire Transfer</value></data>
|
||||||
|
<data name="dataList.PaymentMethod.MOVIL" xml:space="preserve"><value>Phone</value></data>
|
||||||
|
<data name="dataList.PaymentMethod.OTRO" xml:space="preserve"><value>Other</value></data>
|
||||||
|
|
||||||
</root>
|
</root>
|
||||||
@@ -137,6 +137,19 @@
|
|||||||
<data name="dto.GuestDocument.CreateTime" xml:space="preserve"><value>Creation Time</value></data>
|
<data name="dto.GuestDocument.CreateTime" xml:space="preserve"><value>Creation Time</value></data>
|
||||||
<data name="dto.GuestDocument.UpdateTime" xml:space="preserve"><value>Update Time</value></data>
|
<data name="dto.GuestDocument.UpdateTime" xml:space="preserve"><value>Update Time</value></data>
|
||||||
|
|
||||||
|
<data name="dto.StayEntry.Id" xml:space="preserve"><value>Id</value></data>
|
||||||
|
<data name="dto.StayEntry.DateIn" xml:space="preserve"><value>Date In</value></data>
|
||||||
|
<data name="dto.StayEntry.DateOut" xml:space="preserve"><value>Date Out</value></data>
|
||||||
|
<data name="dto.StayEntry.RoomCount" xml:space="preserve"><value>Room Count</value></data>
|
||||||
|
<data name="dto.StayEntry.RoomNumber" xml:space="preserve"><value>Room Number</value></data>
|
||||||
|
<data name="dto.StayEntry.PaymentMethod" xml:space="preserve"><value>Payment Method</value></data>
|
||||||
|
<data name="dto.StayEntry.GuestDocuments" xml:space="preserve"><value>Guests</value></data>
|
||||||
|
<data name="dto.StayEntry.CreateTime" xml:space="preserve"><value>Creation Time</value></data>
|
||||||
|
<data name="dto.StayEntry.UpdateTime" xml:space="preserve"><value>Update Time</value></data>
|
||||||
|
|
||||||
|
<data name="tmp" xml:space="preserve"><value>TMP</value></data>
|
||||||
|
|
||||||
|
<data name="general.actions" xml:space="preserve"><value>Actions</value></data>
|
||||||
<data name="general.reloadData" xml:space="preserve"><value>Reload Data</value></data>
|
<data name="general.reloadData" xml:space="preserve"><value>Reload Data</value></data>
|
||||||
<data name="general.inProgressMsg" xml:space="preserve"><value>In Progress...</value></data>
|
<data name="general.inProgressMsg" xml:space="preserve"><value>In Progress...</value></data>
|
||||||
<data name="general.ConfigureColumns" xml:space="preserve"><value>Configure Columns</value></data>
|
<data name="general.ConfigureColumns" xml:space="preserve"><value>Configure Columns</value></data>
|
||||||
@@ -151,6 +164,7 @@
|
|||||||
<data name="general.btnSave" xml:space="preserve"><value>Save</value></data>
|
<data name="general.btnSave" xml:space="preserve"><value>Save</value></data>
|
||||||
<data name="general.btnCancel" xml:space="preserve"><value>Cancel</value></data>
|
<data name="general.btnCancel" xml:space="preserve"><value>Cancel</value></data>
|
||||||
<data name="general.noResults" xml:space="preserve"><value>No Results!</value></data>
|
<data name="general.noResults" xml:space="preserve"><value>No Results!</value></data>
|
||||||
|
<data name="general.showAllElements" xml:space="preserve"><value>Show all elements</value></data>
|
||||||
<data name="general.wildcardHelperText" xml:space="preserve"><value>Use '%' as wildcard</value></data>
|
<data name="general.wildcardHelperText" xml:space="preserve"><value>Use '%' as wildcard</value></data>
|
||||||
|
|
||||||
<data name="general.address.address" xml:space="preserve"><value>Address</value></data>
|
<data name="general.address.address" xml:space="preserve"><value>Address</value></data>
|
||||||
@@ -163,20 +177,32 @@
|
|||||||
<data name="page.GuestDocList.pageTitle" xml:space="preserve"><value>Guest Documents</value></data>
|
<data name="page.GuestDocList.pageTitle" xml:space="preserve"><value>Guest Documents</value></data>
|
||||||
<data name="page.GuestDocList.documentList" xml:space="preserve"><value>Document List</value></data>
|
<data name="page.GuestDocList.documentList" xml:space="preserve"><value>Document List</value></data>
|
||||||
<data name="page.GuestDocList.btnNewGuest" xml:space="preserve"><value>New Guest</value></data>
|
<data name="page.GuestDocList.btnNewGuest" xml:space="preserve"><value>New Guest</value></data>
|
||||||
<data name="page.GuestDocList.showAllElements" xml:space="preserve"><value>Show all elements</value></data>
|
|
||||||
|
|
||||||
<data name="page.GuestDocNew.msgAlreadyExists" xml:space="preserve"><value>This Guest Document Already exists!!</value></data>
|
<data name="page.GuestDocNew.msgAlreadyExists" xml:space="preserve"><value>This Guest Document Already exists!!</value></data>
|
||||||
<data name="page.GuestDocNew.btnGoExistingDoc" xml:space="preserve"><value>Go to existing document</value></data>
|
<data name="page.GuestDocNew.btnGoExistingDoc" xml:space="preserve"><value>Go to existing document</value></data>
|
||||||
|
|
||||||
|
<data name="page.StayEntryList.pageTitle" xml:space="preserve"><value>Stay Entries</value></data>
|
||||||
|
<data name="page.StayEntryList.entryList" xml:space="preserve"><value>Entry List</value></data>
|
||||||
|
<data name="page.StayEntryList.btnNewStay" xml:space="preserve"><value>New Stay</value></data>
|
||||||
|
|
||||||
|
<data name="page.StayEntryNew.pageTitle" xml:space="preserve"><value>New Stay</value></data>
|
||||||
|
|
||||||
<data name="control.GuestDocForm.sectionDocument" xml:space="preserve"><value>Document Details</value></data>
|
<data name="control.GuestDocForm.sectionDocument" xml:space="preserve"><value>Document Details</value></data>
|
||||||
<data name="control.GuestDocForm.sectionGuest" xml:space="preserve"><value>Guest Details</value></data>
|
<data name="control.GuestDocForm.sectionGuest" xml:space="preserve"><value>Guest Details</value></data>
|
||||||
<data name="control.GuestDocForm.sectionContact" xml:space="preserve"><value>Contact Details</value></data>
|
<data name="control.GuestDocForm.sectionContact" xml:space="preserve"><value>Contact Details</value></data>
|
||||||
<data name="control.GuestDocForm.sectionAddress" xml:space="preserve"><value>Guest Address</value></data>
|
<data name="control.GuestDocForm.sectionAddress" xml:space="preserve"><value>Guest Address</value></data>
|
||||||
<data name="control.GuestDocForm.btnSearchAddress" xml:space="preserve"><value>Search Address</value></data>
|
<data name="control.GuestDocForm.btnSearchAddress" xml:space="preserve"><value>Search Address</value></data>
|
||||||
|
|
||||||
|
<data name="control.StayEntryForm.sectionDetails" xml:space="preserve"><value>Stay Details</value></data>
|
||||||
|
<data name="control.StayEntryForm.sectionGuests" xml:space="preserve"><value>Guest List</value></data>
|
||||||
|
<data name="control.StayEntryForm.btnAddGuest" xml:space="preserve"><value>Add Guest</value></data>
|
||||||
|
|
||||||
<data name="control.AddressQueryDialog.dialogTitle" xml:space="preserve"><value>Search Address</value></data>
|
<data name="control.AddressQueryDialog.dialogTitle" xml:space="preserve"><value>Search Address</value></data>
|
||||||
<data name="control.AddressQueryDialog.searchText" xml:space="preserve"><value>Search Address</value></data>
|
<data name="control.AddressQueryDialog.searchText" xml:space="preserve"><value>Search Address</value></data>
|
||||||
<data name="control.AddressQueryDialog.btnSearch" xml:space="preserve"><value>Search Address</value></data>
|
<data name="control.AddressQueryDialog.btnSearch" xml:space="preserve"><value>Search Address</value></data>
|
||||||
<data name="control.AddressQueryDialog.btnSelectAddress" xml:space="preserve"><value>Use Address</value></data>
|
<data name="control.AddressQueryDialog.btnSelectAddress" xml:space="preserve"><value>Use Address</value></data>
|
||||||
|
|
||||||
|
<data name="control.GuestDocumentSearchDialog.dialogTitle" xml:space="preserve"><value>Search Guest Document</value></data>
|
||||||
|
<data name="control.GuestDocumentSearchDialog.btnSelectDocument" xml:space="preserve"><value>Use Guest</value></data>
|
||||||
|
|
||||||
</root>
|
</root>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Somnia.GuestLog.Infrastructure;
|
using Somnia.GuestLog.Infrastructure;
|
||||||
|
using Somnia.GuestLog.Models;
|
||||||
using Somnia.GuestLog.Models.DTOs;
|
using Somnia.GuestLog.Models.DTOs;
|
||||||
using Somnia.GuestLog.Models.Entities;
|
using Somnia.GuestLog.Models.Entities;
|
||||||
using Somnia.GuestLog.Utils;
|
using Somnia.GuestLog.Utils;
|
||||||
@@ -35,6 +36,7 @@ public class GuestDocumentService(
|
|||||||
ZipCode = dto.ZipCode,
|
ZipCode = dto.ZipCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DateTime createTime = DateTime.UtcNow;
|
||||||
GuestDocument dbItem = new()
|
GuestDocument dbItem = new()
|
||||||
{
|
{
|
||||||
DocumentType = dto.DocumentType!,
|
DocumentType = dto.DocumentType!,
|
||||||
@@ -50,8 +52,8 @@ public class GuestDocumentService(
|
|||||||
PhoneNumber = dto.PhoneNumber,
|
PhoneNumber = dto.PhoneNumber,
|
||||||
EmailAddress = dto.EmailAddress,
|
EmailAddress = dto.EmailAddress,
|
||||||
AddressDetails = addressItem,
|
AddressDetails = addressItem,
|
||||||
CreateTime = DateTime.UtcNow,
|
CreateTime = createTime,
|
||||||
UpdateTime = DateTime.UtcNow,
|
UpdateTime = createTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -125,7 +127,7 @@ public class GuestDocumentService(
|
|||||||
.OrderByDescending(e => e.UpdateTime)
|
.OrderByDescending(e => e.UpdateTime)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return dbList.Select(x => GetDtoFromDb(x));
|
return dbList.Select(GetDtoFromDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -163,30 +165,13 @@ public class GuestDocumentService(
|
|||||||
return dbList.Select(x => GetDtoFromDb(x));
|
return dbList.Select(x => GetDtoFromDb(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuestDocumentDTO GetDtoFromDb(GuestDocument dbItem)
|
|
||||||
|
#region Internal Methods
|
||||||
|
|
||||||
|
private static GuestDocumentDTO GetDtoFromDb(GuestDocument dbItem)
|
||||||
{
|
{
|
||||||
return new()
|
return EntityMapping.MapGuestDocumentEntityToDTO(dbItem);
|
||||||
{
|
|
||||||
DocumentType = dbItem.DocumentType,
|
|
||||||
DocumentNum = dbItem.DocumentNum,
|
|
||||||
IssueDate = dbItem.IssueDate.ToDateTime(TimeOnly.MinValue),
|
|
||||||
SupportNum = dbItem.SupportNum,
|
|
||||||
Nationality = dbItem.Nationality,
|
|
||||||
Name = dbItem.Name,
|
|
||||||
Surname = dbItem.Surname,
|
|
||||||
Surname2 = dbItem.Surname2,
|
|
||||||
BirthDate = dbItem.BirthDate.ToDateTime(TimeOnly.MinValue),
|
|
||||||
Gender = dbItem.Gender,
|
|
||||||
PhoneNumber = dbItem.PhoneNumber,
|
|
||||||
EmailAddress = dbItem.EmailAddress,
|
|
||||||
Address = dbItem.AddressDetails?.Address ?? "",
|
|
||||||
AddressCity = dbItem.AddressDetails?.AddressCity ?? "",
|
|
||||||
AddressProvince = dbItem.AddressDetails?.AddressProvince ?? "",
|
|
||||||
AddressState = dbItem.AddressDetails?.AddressState ?? "",
|
|
||||||
AddressCountry = dbItem.AddressDetails?.AddressCountry! ?? "",
|
|
||||||
ZipCode = dbItem.AddressDetails?.ZipCode ?? "",
|
|
||||||
CreateTime = dbItem.CreateTime,
|
|
||||||
UpdateTime = dbItem.UpdateTime,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Somnia.GuestLog.Models.DTOs;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Services;
|
||||||
|
|
||||||
|
public interface IStayEntryService
|
||||||
|
{
|
||||||
|
public Task<bool> CreateEntryAsync(StayEntryDTO dto);
|
||||||
|
public Task<bool> UpdateEntryAsync(StayEntryDTO updatedDto);
|
||||||
|
public Task<bool> DeleteEntryAsync(StayEntryDTO dto);
|
||||||
|
public Task<bool> DeleteEntryAsync(long id);
|
||||||
|
|
||||||
|
public Task<StayEntryDTO?> GetDtoByIdAsync(long id);
|
||||||
|
public Task<IEnumerable<StayEntryDTO>> GetDtoListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
public Task<bool> IsGuestInStayInPeriod(string docType, string docNum, DateTime startTime, DateTime endTime);
|
||||||
|
public Task<IEnumerable<StayEntryDTO>> GetStaysWithGuest(string docType, string docNum);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ public class StaticDataListService(
|
|||||||
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_DocumentTypes, _documentTypeSet),
|
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_GenderOptions, _genderOptionSet),
|
||||||
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_CountryCodes, _countryCodeSet),
|
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_CountryCodes, _countryCodeSet),
|
||||||
|
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_PaymentMethods, _paymentMethodSet),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
public List<string> GetAvailableLists()
|
public List<string> GetAvailableLists()
|
||||||
@@ -92,6 +93,14 @@ public class StaticDataListService(
|
|||||||
"VIR","VNM","VUT","WLF","WSM","YEM","ZAF","ZMB","ZWE",
|
"VIR","VNM","VUT","WLF","WSM","YEM","ZAF","ZMB","ZWE",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static readonly HashSet<string> _paymentMethodSet = [
|
||||||
|
"EFECT",
|
||||||
|
"TARJT",
|
||||||
|
"TRANS",
|
||||||
|
"MOVIL",
|
||||||
|
"OTRO",
|
||||||
|
];
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Somnia.GuestLog.Infrastructure;
|
||||||
|
using Somnia.GuestLog.Models;
|
||||||
|
using Somnia.GuestLog.Models.DTOs;
|
||||||
|
using Somnia.GuestLog.Models.Entities;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Services;
|
||||||
|
|
||||||
|
public class StayEntryService(
|
||||||
|
ILogger<StayEntryService> logger,
|
||||||
|
IDbContextFactory<GuestLogContext> contextFactory,
|
||||||
|
IValidator<StayEntryDTO> dtoValidator
|
||||||
|
) : IStayEntryService
|
||||||
|
{
|
||||||
|
public async Task<bool> CreateEntryAsync(StayEntryDTO dto)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(dto);
|
||||||
|
|
||||||
|
var valResult = await dtoValidator.ValidateAsync(dto);
|
||||||
|
if (!valResult.IsValid)
|
||||||
|
{
|
||||||
|
logger.LogWarning("StayEntryService - CreateEntryAsync: Dto validation failed. Fix the errors: {errorList}", valResult.Errors);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime createTime = DateTime.UtcNow;
|
||||||
|
StayEntry dbStay = new()
|
||||||
|
{
|
||||||
|
DateIn = dto.DateIn!.Value.ToUniversalTime(),
|
||||||
|
DateOut = dto.DateOut!.Value.ToUniversalTime(),
|
||||||
|
RoomCount = dto.RoomCount!.Value,
|
||||||
|
RoomNumber = dto.RoomNumber,
|
||||||
|
PaymentMethod = dto.PaymentMethod!,
|
||||||
|
CreateTime = createTime,
|
||||||
|
UpdateTime = createTime,
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var dbContext = contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
//Check and add GuestDocuments
|
||||||
|
foreach (GuestDocumentDTO guestDto in dto.GuestDocuments)
|
||||||
|
{
|
||||||
|
//Get it from db.
|
||||||
|
GuestDocument? dbGuest = await dbContext.GuestDocuments.FindAsync(guestDto.DocumentType, guestDto.DocumentNum)
|
||||||
|
?? throw new InvalidOperationException($"GuestDocument not found! Id: '{guestDto.FullKey}'");
|
||||||
|
|
||||||
|
//Check if Guest is already in other stay during the same period.
|
||||||
|
bool isInOtherStay = await this.IsGuestInStayInPeriod(dbGuest.DocumentType, dbGuest.DocumentNum, dbStay.DateIn, dbStay.DateOut);
|
||||||
|
if (isInOtherStay)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Guest ('{dbGuest.GetFullKey()}') is already in a stay during the period: {dbStay.DateIn}-{dbStay.DateOut}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add dbGuest to dbStay.
|
||||||
|
dbStay.GuestDocuments.Add(dbGuest);
|
||||||
|
}
|
||||||
|
|
||||||
|
await dbContext.AddAsync(dbStay);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
logger.LogInformation("StayEntryService - CreateEntryAsync: StayEntry Created: '{id}'", dbStay.GetFullKey());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "StayEntryService - CreateEntryAsync: Error creating StayEntry");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> UpdateEntryAsync(StayEntryDTO updatedDto)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> DeleteEntryAsync(StayEntryDTO dto)
|
||||||
|
{
|
||||||
|
if (dto.Id is null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("StayEntryService - DeleteEntry: A DTO without key can't be deleted!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return DeleteEntryAsync(dto.Id.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> DeleteEntryAsync(long id)
|
||||||
|
{
|
||||||
|
using var dbContext = contextFactory.CreateDbContext();
|
||||||
|
StayEntry? dbItem = await dbContext.StayEntries.FindAsync(id);
|
||||||
|
if (dbItem is null)
|
||||||
|
{
|
||||||
|
logger.LogWarning("StayEntryService - DeleteEntry: Error deleting StayEntry. Entity not found with key: '{key}'", id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dbContext.StayEntries.Remove(dbItem);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
logger.LogInformation("StayEntryService - DeleteEntry: StayEntry deleted: '{id}'", dbItem.GetFullKey());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "StayEntryService - DeleteEntry: Error deleting StayEntry: '{id}'", dbItem.GetFullKey());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StayEntryDTO?> GetDtoByIdAsync(long id)
|
||||||
|
{
|
||||||
|
using var dbContext = contextFactory.CreateDbContext();
|
||||||
|
StayEntry? dbItem = await dbContext.StayEntries.FindAsync(id);
|
||||||
|
return dbItem is not null ? GetDtoFromDb(dbItem) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<StayEntryDTO>> GetDtoListAsync()
|
||||||
|
{
|
||||||
|
using var dbContext = contextFactory.CreateDbContext();
|
||||||
|
var dbList = await dbContext.StayEntries
|
||||||
|
.OrderByDescending(e => e.UpdateTime)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return dbList.Select(GetDtoFromDb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> IsGuestInStayInPeriod(string docType, string docNum, DateTime startTime, DateTime endTime)
|
||||||
|
{
|
||||||
|
using var dbContext = contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
bool rs = await dbContext.StayEntries.AnyAsync(
|
||||||
|
s => s.DateIn < endTime && s.DateOut > startTime
|
||||||
|
&& s.GuestDocuments.Any(g => g.DocumentType == docType && g.DocumentNum == docNum));
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<StayEntryDTO>> GetStaysWithGuest(string docType, string docNum)
|
||||||
|
{
|
||||||
|
using var dbContext = contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
var rs = await dbContext.StayEntries.Where(
|
||||||
|
s => s.GuestDocuments.Any(g => g.DocumentType == docType && g.DocumentNum == docNum))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return rs.Select(GetDtoFromDb);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Internal Methods
|
||||||
|
|
||||||
|
private static StayEntryDTO GetDtoFromDb(StayEntry dbItem)
|
||||||
|
{
|
||||||
|
return EntityMapping.MapStayEntryEntityToDTO(dbItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using Somnia.GuestLog.Models.DTOs;
|
||||||
|
using Somnia.GuestLog.Services;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Validators;
|
||||||
|
|
||||||
|
public class StayEntryDTOValidator : ValueValidator<StayEntryDTO>
|
||||||
|
{
|
||||||
|
public StayEntryDTOValidator(IDataListService dataListService)
|
||||||
|
{
|
||||||
|
RuleFor(e => e.DateIn)
|
||||||
|
.NotEmpty()
|
||||||
|
.LessThanOrEqualTo(DateTime.Today.AddDays(1).AddSeconds(-1));
|
||||||
|
|
||||||
|
RuleFor(e => e.DateOut)
|
||||||
|
.NotEmpty()
|
||||||
|
.GreaterThan(DateTime.Today);
|
||||||
|
|
||||||
|
RuleFor(e => e.RoomCount)
|
||||||
|
.NotEmpty()
|
||||||
|
.GreaterThan(0);
|
||||||
|
|
||||||
|
RuleFor(e => e.PaymentMethod)
|
||||||
|
.Cascade(CascadeMode.Stop)
|
||||||
|
.NotEmpty()
|
||||||
|
.Must(val => val != null && dataListService.IsValueInList(GuestConsts.DataList_PaymentMethods, val));
|
||||||
|
|
||||||
|
RuleFor(e => e.GuestDocuments)
|
||||||
|
.NotEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Validators;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for validators that will be used by MudForms.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type that is validated</typeparam>
|
||||||
|
public abstract class ValueValidator<T> : AbstractValidator<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Method used by MudForm to validate properties.
|
||||||
|
/// </summary>
|
||||||
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||||
|
{
|
||||||
|
var result = await ValidateAsync(ValidationContext<T>.CreateWithOptions((T)model, x =>
|
||||||
|
x.IncludeProperties(propertyName)));
|
||||||
|
return result.IsValid ? [] : result.Errors.Select(e => e.ErrorMessage);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user