Files
gpw_next/GPW.CORE.WRKLOG/Components/Compo/RegMalattia.razor.cs
T
samuele b1afa82a91 Continuo spostamento servizi in Data:
- GpwDataSrvice
- MessageService
- ogni dipendenza (aggiunti using, in _import non basta...)
2024-09-07 11:40:28 +02:00

165 lines
4.4 KiB
C#

using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace GPW.CORE.WRKLOG.Components.Compo
{
public partial class RegMalattia
{
#region Public Properties
[Parameter]
public int IdxDipendente { get; set; }
[Parameter]
public bool isLoading { get; set; }
#endregion Public Properties
#region Protected Fields
private bool isSendingData = false;
private int sendDataVal = 0;
private int sendDataNextVal = 0;
private int sendDataMaxVal = 100;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MessageService AppMServ { get; set; } = null!;
[Inject]
protected GpwDataService DataService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private List<RegMalattieModel>? ListRecords = null;
private bool showAdd = false;
#endregion Private Fields
#region Private Properties
private RegMalattieModel currRecord { get; set; } = new RegMalattieModel();
private string NomeDip
{
get
{
string answ = "per cortesia";
if (AppMServ != null && AppMServ.RigaDip != null)
{
answ = $"{AppMServ.RigaDip.Nome}";
}
return answ;
}
}
#endregion Private Properties
#region Private Methods
private async Task DeleteRec(RegMalattieModel selItem)
{
// chiedo verifica
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record selezionato??"))
return;
isSendingData = true;
sendDataVal = 0;
sendDataNextVal = 90;
await InvokeAsync(StateHasChanged);
await Task.Delay(1);
var updTask = Task.Run(async () =>
await DataService.RegMalattieDelete(selItem)
);
await updTask;
sendDataVal = 100;
sendDataNextVal = 100;
await Task.Delay(1);
await ReloadData();
await ReportUpdate.InvokeAsync(true);
isSendingData = false;
}
private void editRec(RegMalattieModel selItem)
{
currRecord = selItem;
showAdd = true;
}
/// <summary>
/// Registra il record
/// </summary>
/// <returns></returns>
private async Task insertRecord()
{
isSendingData = true;
sendDataVal = 0;
sendDataNextVal = 5;
await Task.Delay(1);
// forzo dipendente
currRecord.IdxDipendente = AppMServ.IdxDipendente;
await Task.Delay(1);
// effettuo insert...
sendDataVal = 5;
sendDataNextVal = 90;
await Task.Delay(1);
var updTask = Task.Run(async () =>
await DataService.RegMalattieUpsert(currRecord)
);
await updTask;
// effettuo insert...
sendDataVal = 100;
sendDataNextVal = 100;
// aggiorno display...
await Task.Delay(1);
showAdd = false;
await ReloadData();
await ReportUpdate.InvokeAsync(true);
isSendingData = false;
}
[Parameter]
public EventCallback<bool> ReportUpdate { get; set; }
private async Task ReloadData()
{
ListRecords = null;
await Task.Delay(1);
ListRecords = await DataService.RegMalattieGetByDip(IdxDipendente, 10);
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
}
private async Task toggleAddNew()
{
showAdd = !showAdd;
await Task.Delay(1);
if (showAdd)
{
currRecord = new RegMalattieModel() { IdxDipendente = AppMServ.IdxDipendente };
}
}
#endregion Private Methods
}
}