Files
magman/MagMan.UI/Components/MachineMan.razor.cs
T
2024-01-12 11:53:03 +01:00

135 lines
3.4 KiB
C#

// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this
// file to you under the MIT license.
using EgwCoreLib.Razor;
using MagMan.Data.Admin.DbModels;
using MagMan.Data.Admin.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace MagMan.UI.Components
{
public partial class MachineMan
{
#region Public Properties
[Parameter]
public int CustomerId { get; set; } = 0;
#endregion Public Properties
#region Protected Properties
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MultiTenantService MTService { get; set; } = null!;
protected int totalCount { get; set; } = 0;
#endregion Protected Properties
#region Protected Methods
protected async Task CreateNew()
{
CurrItem = new MachineModel()
{
Name = "Nuova Macchina",
Note = "...",
CustomerID = CustomerId
};
await InvokeAsync(StateHasChanged);
}
protected async Task DeleteRecord(MachineModel selItem)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
return;
await MTService.MachineDelete(selItem);
await ReloadData();
}
protected void DoSelect(MachineModel? selItem)
{
CurrItem = selItem;
}
protected async Task ForceReload(bool force)
{
CurrItem = null;
await ReloadData();
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
protected void SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
}
protected void SetPage(int newNum)
{
currPage = newNum;
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private MachineModel? CurrItem = null;
private List<MachineModel>? ListRecords = null;
private List<MachineModel>? SearchRecords = null;
private bool sortAsc = true;
private string sortField = "";
#endregion Private Fields
#region Private Properties
private int currPage { get; set; } = 1;
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 10;
#endregion Private Properties
#region Private Methods
private async Task ReloadData()
{
isLoading = true;
ListRecords = null;
SearchRecords = await MTService.MachineGetFilt(CustomerId);
totalCount = SearchRecords.Count;
ListRecords = SearchRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
}
private string textCss(bool isActive)
{
return isActive ? "text-dark" : "text-secondary text-decoration-line-through";
}
#endregion Private Methods
}
}