SHA256
Compare commits
3
Commits
8232e7d7c9
...
3e0ef34f66
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
3e0ef34f66 | ||
|
|
6dc2d2426b | ||
|
|
ec7efd867b |
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -26,7 +26,7 @@
|
||||
}
|
||||
</MudSelect>
|
||||
<MudTextField @bind-Value="Model.DocumentNum" For="@(() => Model.DocumentNum)" Label="@LanguageLocale.dto_GuestDocument_DocumentNum"
|
||||
Immediate="true" Required ReadOnly="@ReadOnlyDocId" />
|
||||
Required ReadOnly="@ReadOnlyDocId" />
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row style="@FieldMarginY">
|
||||
@@ -34,7 +34,7 @@
|
||||
Clearable OpenTo="OpenTo.Year" Editable />
|
||||
|
||||
<MudTextField @bind-Value="Model.SupportNum" For="@(() => Model.SupportNum)" Label="@LanguageLocale.dto_GuestDocument_SupportNum"
|
||||
Immediate="true" Required="@isSuportNumberRequired" Mask="@(new PatternMask("aaa000000"))"
|
||||
Required="@isSuportNumberRequired" Mask="@(new PatternMask("aaa000000"))"
|
||||
OnBlur="@(() => Model.SupportNum = Model.SupportNum?.ToUpper())" />
|
||||
</MudStack>
|
||||
|
||||
@@ -51,13 +51,13 @@
|
||||
|
||||
<MudTextField @bind-Value="Model.Name" For="@(() => Model.Name)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_Name"
|
||||
Immediate="true" OnBlur="@(() => Model.Name = Model.Name?.ToUpper())" />
|
||||
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())" />
|
||||
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())" />
|
||||
OnBlur="@(() => Model.Surname2 = Model.Surname2?.ToUpper())" />
|
||||
|
||||
<MudStack Row style="@FieldMarginY">
|
||||
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="@LanguageLocale.dto_GuestDocument_BirthDate"
|
||||
@@ -83,10 +83,10 @@
|
||||
<MudStack Row>
|
||||
<MudTextField @bind-Value="Model.PhoneNumber" For="@(() => Model.PhoneNumber)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_PhoneNumber"
|
||||
InputType="InputType.Telephone" Immediate="true" />
|
||||
InputType="InputType.Telephone" />
|
||||
<MudTextField @bind-Value="Model.EmailAddress" For="@(() => Model.EmailAddress)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_EmailAddress"
|
||||
InputType="InputType.Email" Immediate="true" />
|
||||
InputType="InputType.Email" />
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
@@ -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="@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>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
@page "/debug/empty"
|
||||
|
||||
|
||||
@inject ILogger<Empty> logger;
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<PageTitle>DEBUG - Empty</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h3" GutterBottom="true" Class="mt-2">Empty Page for Debug</MudText>
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
@@ -7,9 +7,7 @@
|
||||
@inject IDialogService DialogService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentService guestDocService
|
||||
|
||||
|
||||
@inject FluentValidation.IValidator<GuestDocIdDTO> docIdValidator;
|
||||
@inject IStayEntryService stayService
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - Details</PageTitle>
|
||||
@@ -17,8 +15,8 @@
|
||||
<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()">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Edit"
|
||||
OnClick="() => BtnEdit()" Disabled>
|
||||
@LanguageLocale.general_btnEdit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
||||
@@ -29,7 +27,46 @@
|
||||
|
||||
@if (documentModel is not null)
|
||||
{
|
||||
<GuestDocForm @ref="_form" Model="documentModel" ReadOnly="true" />
|
||||
<MudTabs Elevation="3" Rounded="true" ApplyEffectsToContainer="true" TabPanelsClass="pa-4" KeepPanelsAlive="true"
|
||||
Centered>
|
||||
|
||||
<MudTabPanel Text="Details" Icon="@Icons.Material.Filled.Info">
|
||||
<GuestDocForm @ref="_form" Model="documentModel" ReadOnly="true" />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Stays" ToolTip="Guest stays" OnClick="LoadTabGuestStays" Icon="@Icons.Material.Filled.Bed">
|
||||
<MudText>Total Stays: @(guestStaysLoading ? "Loading..." : guestStayList.Count())</MudText>
|
||||
<MudTable Items="@guestStayList" Hover="true" Loading="@guestStaysLoading" Class="mt-2" Elevation="2">
|
||||
<HeaderContent>
|
||||
<MudTh>@LanguageLocale.dto_StayEntry_DateIn</MudTh>
|
||||
<MudTh>@LanguageLocale.dto_StayEntry_DateOut</MudTh>
|
||||
<MudTh>@LanguageLocale.dto_StayEntry_RoomCount</MudTh>
|
||||
<MudTh>@LanguageLocale.dto_StayEntry_RoomNumber</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="@LanguageLocale.dto_StayEntry_DateIn">
|
||||
@context.DateIn
|
||||
</MudTd>
|
||||
<MudTd DataLabel="@LanguageLocale.dto_StayEntry_DateOut">
|
||||
@context.DateOut
|
||||
</MudTd>
|
||||
<MudTd DataLabel="@LanguageLocale.dto_StayEntry_RoomCount">
|
||||
@context.RoomCount
|
||||
</MudTd>
|
||||
<MudTd DataLabel="@LanguageLocale.dto_StayEntry_RoomNumber">
|
||||
@context.RoomNumber
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
<MudText>@LanguageLocale.general_noResults</MudText>
|
||||
</NoRecordsContent>
|
||||
<LoadingContent>
|
||||
<MudSkeleton Height="50px" Class="mx-4" />
|
||||
</LoadingContent>
|
||||
</MudTable>
|
||||
</MudTabPanel>
|
||||
|
||||
</MudTabs>
|
||||
}
|
||||
|
||||
@code {
|
||||
@@ -42,6 +79,10 @@
|
||||
GuestDocumentDTO? documentModel = null;
|
||||
|
||||
|
||||
IEnumerable<StayEntryDTO> guestStayList = [];
|
||||
bool guestStaysLoading = true;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (docId is null)
|
||||
@@ -78,4 +119,22 @@
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
|
||||
private async Task LoadTabGuestStays()
|
||||
{
|
||||
//Only load when there is no data.
|
||||
if (guestStayList.Count() > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (documentModel is null || documentModel.DocumentType is null || documentModel.DocumentNum is null)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
guestStaysLoading = true;
|
||||
guestStayList = await stayService.GetStaysWithGuest(documentModel.DocumentType, documentModel.DocumentNum);
|
||||
guestStaysLoading = false;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
<MudText Typo="Typo.h4" GutterBottom="true">@LanguageLocale.page_GuestDocList_pageTitle</MudText>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.Search" OnClick="() => SearchDataAsync()">
|
||||
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"
|
||||
@@ -26,31 +26,7 @@
|
||||
</MudStack>
|
||||
|
||||
<MudPaper Class="pa-4 my-4" Elevation="2" Height="100%">
|
||||
<MudForm Model="@docFilter">
|
||||
<MudStack Row Breakpoint="Breakpoint.LgAndDown" StretchItems="StretchItems.All">
|
||||
<MudStack Row style="margin-block: 0.2em;">
|
||||
<MudSelect @bind-Value="docFilter.DocumentType" For="@(() => docFilter.DocumentType)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_DocumentType">
|
||||
@foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes))
|
||||
{
|
||||
<MudSelectItem Value="docType">
|
||||
@dataListService.GetLocalizedValue(GuestConsts.DataList_DocumentTypes, docType)
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudTextField @bind-Value="docFilter.DocumentNumber" For="@(() => docFilter.DocumentNumber)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_DocumentNum" />
|
||||
</MudStack>
|
||||
<MudStack Row style="margin-block: 0.2em;">
|
||||
<MudTextField @bind-Value="docFilter.Name" For="@(() => docFilter.Name)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_Name"
|
||||
HelperText="@LanguageLocale.general_wildcardHelperText" HelperTextOnFocus="true" />
|
||||
<MudTextField @bind-Value="docFilter.Surname" For="@(() => docFilter.Surname)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_Surname"
|
||||
HelperText="@LanguageLocale.general_wildcardHelperText" HelperTextOnFocus="true" />
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</MudForm>
|
||||
<GuestDocumentFilterForm @bind-Filter="docFilter" />
|
||||
</MudPaper>
|
||||
|
||||
<MudDataGrid @ref="_dataGrid" T="GuestDocumentDTO" Items="@guestDocList" Loading="@_dataLoading" ReadOnly="true"
|
||||
@@ -58,7 +34,7 @@
|
||||
<ToolBarContent>
|
||||
<MudText Typo="Typo.subtitle1">@LanguageLocale.page_GuestDocList_documentList</MudText>
|
||||
<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" />
|
||||
<MudButton StartIcon="@Icons.Material.Outlined.ViewColumn" Variant="Variant.Outlined" Size="Size.Small"
|
||||
OnClick="(args) => BtnConfigureColumnsClick(args)">
|
||||
@@ -126,14 +102,6 @@
|
||||
|
||||
#region Data Loading
|
||||
|
||||
private async Task SearchDataAsync()
|
||||
{
|
||||
docFilter.Name = docFilter.Name?.ToUpper();
|
||||
docFilter.Surname = docFilter.Surname?.ToUpper();
|
||||
|
||||
await LoadDataAsync();
|
||||
}
|
||||
|
||||
private async Task LoadDataAsync(bool showMsg = true)
|
||||
{
|
||||
_dataLoading = true;
|
||||
@@ -152,23 +120,27 @@
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private async Task BtnSearchDataAsync()
|
||||
{
|
||||
docFilter.Name = docFilter.Name?.ToUpper();
|
||||
docFilter.Surname = docFilter.Surname?.ToUpper();
|
||||
|
||||
await LoadDataAsync();
|
||||
}
|
||||
|
||||
private async Task BtnConfigureColumnsClick(MouseEventArgs args)
|
||||
{
|
||||
_dataGrid.ShowColumnsPanel(args);
|
||||
}
|
||||
|
||||
|
||||
private async Task BtnViewDetails(GuestDocumentDTO item)
|
||||
{
|
||||
var parameters =
|
||||
new DialogParameters<GuestDocDetailsDialog> { { x => x.DocumentDTO, item } };
|
||||
var options = new DialogOptions()
|
||||
{
|
||||
FullScreen = true,
|
||||
CloseButton = true,
|
||||
CloseOnEscapeKey = true,
|
||||
};
|
||||
GuestDocIdDTO idDto = GuestDocIdDTO.BuildFromDto(item) ?? throw new InvalidOperationException();
|
||||
|
||||
await DialogService.ShowAsync<GuestDocDetailsDialog>("GuestDoc Details", parameters, options);
|
||||
string itemId = GuestDocIdDTO.EncodeAsString(idDto);
|
||||
string uri = GuestConsts.Page_GuestDocs_Detail.Replace(GuestConsts.Page_GuestDocs_Detail_Param_DocId, itemId);
|
||||
Navigation.NavigateTo(uri);
|
||||
}
|
||||
|
||||
private async Task BtnDeleteItem(GuestDocumentDTO item)
|
||||
|
||||
@@ -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.Components
|
||||
@using Somnia.GuestLog.Components.Layout
|
||||
@using Somnia.GuestLog.Components.Forms
|
||||
@using Somnia.GuestLog.Components.Controls
|
||||
@using Somnia.GuestLog.Resources
|
||||
@using System.Linq;
|
||||
@@ -5,12 +5,17 @@ public static class GuestConsts
|
||||
|
||||
public const string Page_GuestDocs_List = "/guest-documents";
|
||||
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/{Page_GuestDocs_Detail_Param_DocId}";
|
||||
public const string Page_GuestDocs_Detail_Param_DocId = "{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_GenderOptions = "GenderOption";
|
||||
public const string DataList_CountryCodes = "CountryCode";
|
||||
public const string DataList_PaymentMethods = "PaymentMethod";
|
||||
|
||||
|
||||
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<StayEntry> StayEntries { get; set; }
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfiguration<GuestDocument>(new GuestDocumentEntityConfig());
|
||||
modelBuilder.ApplyConfiguration<StayEntry>(new StayEntryEntityConfig());
|
||||
|
||||
OnModelCreatingPartial(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);
|
||||
|
||||
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")
|
||||
@@ -112,6 +130,58 @@ namespace Somnia.GuestLog.Infrastructure.Migrations
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class AddressQueryConfig
|
||||
public enum AddressQueryProviderEnum
|
||||
{
|
||||
Nominatim,
|
||||
GoogleApi
|
||||
GoogleApiV4
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,4 +10,11 @@ public class GuestDocFilterDTO
|
||||
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
|
||||
public bool IsEmpty => string.IsNullOrEmpty(DocumentType)
|
||||
&& string.IsNullOrEmpty(DocumentNumber)
|
||||
&& string.IsNullOrEmpty(Name)
|
||||
&& string.IsNullOrEmpty(Surname)
|
||||
&& string.IsNullOrEmpty(PhoneNumber);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,18 @@ public class GuestDocIdDTO
|
||||
DocumentNum = parts[1]
|
||||
};
|
||||
}
|
||||
|
||||
public static GuestDocIdDTO? BuildFromDto(GuestDocumentDTO? dto)
|
||||
{
|
||||
if (dto is null || dto.DocumentType is null || dto.DocumentNum is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
DocumentType = dto.DocumentType,
|
||||
DocumentNum = dto.DocumentNum
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,7 @@ public class GuestDocumentDTO
|
||||
|
||||
public DateTime? CreateTime { 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))],
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,13 @@ builder.Services.AddDbContextFactory<GuestLogContext>(options =>
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
// Add MudBlazor services
|
||||
builder.Services.AddMudServices();
|
||||
builder.Services.AddMudServices(c =>
|
||||
{
|
||||
c.SnackbarConfiguration.PositionClass = MudBlazor.Defaults.Classes.Position.TopCenter;
|
||||
c.SnackbarConfiguration.ShowTransitionDuration = 300;
|
||||
c.SnackbarConfiguration.HideTransitionDuration = 500;
|
||||
c.SnackbarConfiguration.VisibleStateDuration = 10000;
|
||||
});
|
||||
|
||||
// Add components services to the container.
|
||||
builder.Services.AddRazorComponents()
|
||||
@@ -35,9 +41,11 @@ builder.Services.AddHttpClient();
|
||||
// Add Validation Services
|
||||
builder.Services.AddSingleton<IValidator<GuestDocumentDTO>, GuestDocumentDTOValidator>();
|
||||
builder.Services.AddSingleton<IValidator<GuestDocIdDTO>, GuestDocIdDTOValidator>();
|
||||
builder.Services.AddSingleton<IValidator<StayEntryDTO>, StayEntryDTOValidator>();
|
||||
|
||||
// Add Services
|
||||
builder.Services.AddSingleton<IGuestDocumentService, GuestDocumentService>();
|
||||
builder.Services.AddSingleton<IStayEntryService, StayEntryService>();
|
||||
builder.Services.AddSingleton<IDataListService, StaticDataListService>();
|
||||
|
||||
// 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.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>
|
||||
@@ -137,6 +137,19 @@
|
||||
<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.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.inProgressMsg" xml:space="preserve"><value>In Progress...</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.btnCancel" xml:space="preserve"><value>Cancel</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.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.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.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.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.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.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.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.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.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>
|
||||
@@ -12,6 +12,7 @@ public class ConfigFileAddressQueryFactory(
|
||||
public static void RegisterFactoryItems(IServiceCollection services)
|
||||
{
|
||||
services.AddKeyedTransient<IAddressQueryService, NominatimAddressQueryService>(AddressQueryConfig.AddressQueryProviderEnum.Nominatim);
|
||||
services.AddKeyedTransient<IAddressQueryService, GoogleApiAddressQueryService>(AddressQueryConfig.AddressQueryProviderEnum.GoogleApiV4);
|
||||
}
|
||||
|
||||
public IAddressQueryService GetService()
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Somnia.GuestLog.Models.Configuration;
|
||||
using Somnia.GuestLog.Models.DTOs;
|
||||
using Somnia.GuestLog.Utils;
|
||||
|
||||
namespace Somnia.GuestLog.Services.AddressQuery;
|
||||
|
||||
public class GoogleApiAddressQueryService(
|
||||
IHttpClientFactory httpClientFactory,
|
||||
ILogger<GoogleApiAddressQueryService> logger,
|
||||
IOptions<AddressQueryConfig> configOptions
|
||||
) : IAddressQueryService
|
||||
{
|
||||
private const string defaultBaseAddr = "https://geocode.googleapis.com/v4/";
|
||||
private const string defaultUserAgent = "Somnia-GuestLog";
|
||||
private const string apiUri = "geocode/address/";
|
||||
|
||||
private readonly AddressQueryConfig config = configOptions.Value;
|
||||
|
||||
|
||||
public async Task<List<AddressResultDTO>> SearchAddressAsync(string query)
|
||||
{
|
||||
var http = GetHttpClient();
|
||||
List<AddressResultDTO> rsList = [];
|
||||
|
||||
try
|
||||
{
|
||||
string uri = GetRequestUri(query);
|
||||
GeocodeAddressResponse? apiList = await http.GetFromJsonAsync<GeocodeAddressResponse>(uri)
|
||||
?? throw new InvalidOperationException("Response without results??");
|
||||
|
||||
foreach (GeocodeResult result in apiList.Results)
|
||||
{
|
||||
if (result.PostalAddress is null)
|
||||
{
|
||||
logger.LogWarning("Skipping result without PostalAddress. '{result}'", result);
|
||||
continue;
|
||||
}
|
||||
|
||||
string? alpha3CountryCode = CountryCodesUtils.Alpha2ToAlpha3(result.PostalAddress.RegionCode);
|
||||
string? addressLine = result.PostalAddress.AddressLines is not null ? string.Join(", ", result.PostalAddress.AddressLines) : null;
|
||||
|
||||
string[]? formatedParts = result.FormattedAddress?.Split(",");
|
||||
if (formatedParts is not null && formatedParts.Length < 2)
|
||||
{
|
||||
formatedParts = null;
|
||||
}
|
||||
|
||||
rsList.Add(new()
|
||||
{
|
||||
HouseNumber = null,
|
||||
AddressRoad = addressLine,
|
||||
AddressCity = result.PostalAddress.Locality,
|
||||
AddressProvince = result.PostalAddress.AdministrativeArea,
|
||||
AddressState = null,
|
||||
AddressCountry = formatedParts?[^1],
|
||||
ZipCode = result.PostalAddress.PostalCode,
|
||||
AddressCountryCode = alpha3CountryCode
|
||||
});
|
||||
}
|
||||
|
||||
return rsList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error getting info from API!");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
private HttpClient GetHttpClient()
|
||||
{
|
||||
HttpClient client = httpClientFactory.CreateClient();
|
||||
|
||||
Uri baseAddr = new(config.ServiceURL ?? defaultBaseAddr);
|
||||
|
||||
client.BaseAddress = baseAddr;
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(config.UserAgent ?? defaultUserAgent);
|
||||
client.DefaultRequestHeaders.Add("X-Goog-Api-Key", config.ApiKey);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
private string GetRequestUri(string query)
|
||||
{
|
||||
string escapedQuery = Uri.EscapeDataString(query).TrimStart('/');
|
||||
string finalUri = $"{apiUri.TrimEnd('/')}/{escapedQuery}";
|
||||
|
||||
List<KeyValuePair<string, string?>> queryParams = [];
|
||||
if (config.ResultLang is not null)
|
||||
{
|
||||
queryParams.Add(new KeyValuePair<string, string?>("languageCode", config.ResultLang));
|
||||
}
|
||||
|
||||
return QueryHelpers.AddQueryString(finalUri, queryParams);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Models
|
||||
|
||||
private record class PostalAddress(
|
||||
string[]? AddressLines = null,
|
||||
string? PostalCode = null,
|
||||
|
||||
string? AdministrativeArea = null, //Province
|
||||
string? Locality = null, //City
|
||||
string? RegionCode = null //Country Code (CLDR region code)
|
||||
);
|
||||
|
||||
private record class GeocodeResult(
|
||||
string? FormattedAddress = null,
|
||||
PostalAddress? PostalAddress = null
|
||||
);
|
||||
|
||||
private record class GeocodeAddressResponse(
|
||||
GeocodeResult[] Results = null!
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using FluentValidation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Somnia.GuestLog.Infrastructure;
|
||||
using Somnia.GuestLog.Models;
|
||||
using Somnia.GuestLog.Models.DTOs;
|
||||
using Somnia.GuestLog.Models.Entities;
|
||||
using Somnia.GuestLog.Utils;
|
||||
@@ -35,6 +36,7 @@ public class GuestDocumentService(
|
||||
ZipCode = dto.ZipCode,
|
||||
};
|
||||
|
||||
DateTime createTime = DateTime.UtcNow;
|
||||
GuestDocument dbItem = new()
|
||||
{
|
||||
DocumentType = dto.DocumentType!,
|
||||
@@ -50,8 +52,8 @@ public class GuestDocumentService(
|
||||
PhoneNumber = dto.PhoneNumber,
|
||||
EmailAddress = dto.EmailAddress,
|
||||
AddressDetails = addressItem,
|
||||
CreateTime = DateTime.UtcNow,
|
||||
UpdateTime = DateTime.UtcNow,
|
||||
CreateTime = createTime,
|
||||
UpdateTime = createTime,
|
||||
};
|
||||
|
||||
try
|
||||
@@ -125,7 +127,7 @@ public class GuestDocumentService(
|
||||
.OrderByDescending(e => e.UpdateTime)
|
||||
.ToListAsync();
|
||||
|
||||
return dbList.Select(x => GetDtoFromDb(x));
|
||||
return dbList.Select(GetDtoFromDb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -163,30 +165,13 @@ public class GuestDocumentService(
|
||||
return dbList.Select(x => GetDtoFromDb(x));
|
||||
}
|
||||
|
||||
public GuestDocumentDTO GetDtoFromDb(GuestDocument dbItem)
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
private static GuestDocumentDTO GetDtoFromDb(GuestDocument dbItem)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
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,
|
||||
};
|
||||
return EntityMapping.MapGuestDocumentEntityToDTO(dbItem);
|
||||
}
|
||||
|
||||
#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_GenderOptions, _genderOptionSet),
|
||||
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_CountryCodes, _countryCodeSet),
|
||||
new KeyValuePair<string, HashSet<string>>(GuestConsts.DataList_PaymentMethods, _paymentMethodSet),
|
||||
]);
|
||||
|
||||
public List<string> GetAvailableLists()
|
||||
@@ -92,6 +93,14 @@ public class StaticDataListService(
|
||||
"VIR","VNM","VUT","WLF","WSM","YEM","ZAF","ZMB","ZWE",
|
||||
];
|
||||
|
||||
private static readonly HashSet<string> _paymentMethodSet = [
|
||||
"EFECT",
|
||||
"TARJT",
|
||||
"TRANS",
|
||||
"MOVIL",
|
||||
"OTRO",
|
||||
];
|
||||
|
||||
#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
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Somnia.GuestLog.Validators;
|
||||
/// <summary>
|
||||
/// Validator for GuestDocumentDTO which contains multiple rules and can be shared with the back end API
|
||||
/// </summary>
|
||||
public class GuestDocIdDTOValidator : AbstractValidator<GuestDocIdDTO>
|
||||
public class GuestDocIdDTOValidator : ValueValidator<GuestDocIdDTO>
|
||||
{
|
||||
public GuestDocIdDTOValidator(IDataListService dataListService)
|
||||
{
|
||||
@@ -34,11 +34,4 @@ public class GuestDocIdDTOValidator : AbstractValidator<GuestDocIdDTO>
|
||||
.WithMessage("Invalid NIE")
|
||||
.When(x => x.DocumentType == GuestConsts.DocumentType_NIE);
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GuestDocIdDTO>.CreateWithOptions((GuestDocIdDTO)model, x =>
|
||||
x.IncludeProperties(propertyName)));
|
||||
return result.IsValid ? [] : result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Somnia.GuestLog.Validators;
|
||||
/// <summary>
|
||||
/// Validator for GuestDocumentDTO which contains multiple rules and can be shared with the back end API
|
||||
/// </summary>
|
||||
public class GuestDocumentDTOValidator : AbstractValidator<GuestDocumentDTO>
|
||||
public class GuestDocumentDTOValidator : ValueValidator<GuestDocumentDTO>
|
||||
{
|
||||
public GuestDocumentDTOValidator(IDataListService dataListService)
|
||||
{
|
||||
@@ -82,11 +82,4 @@ public class GuestDocumentDTOValidator : AbstractValidator<GuestDocumentDTO>
|
||||
// RuleForEach(x => x.OrderDetails)
|
||||
// .SetValidator(new OrderDetailsModelFluentValidator());
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GuestDocumentDTO>.CreateWithOptions((GuestDocumentDTO)model, x =>
|
||||
x.IncludeProperties(propertyName)));
|
||||
return result.IsValid ? [] : result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -11,8 +11,12 @@
|
||||
"AllowedHosts": "*",
|
||||
"AddressQuery": {
|
||||
"EnableAddressQuery": true,
|
||||
// Nominatim
|
||||
"Provider": "Nominatim",
|
||||
"ServiceURL": "https://nominatim.openstreetmap.org/",
|
||||
// Google Map API
|
||||
// "Provider": "GoogleApiV4",
|
||||
// "ServiceURL": "https://geocode.googleapis.com/v4/",
|
||||
"ApiKey": "",
|
||||
"UserAgent": "Somnia-GuestLog-Dev",
|
||||
"ResultLang": "es"
|
||||
|
||||
Reference in New Issue
Block a user