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="@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>
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,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)">
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user