Files
gpw_next/GPW.CORE.SMART/Components/ProjectsList.razor.cs
T
2023-01-17 12:25:25 +01:00

117 lines
3.2 KiB
C#

using GPW.CORE.Data.DbModels;
using GPW.CORE.Smart.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace GPW.CORE.Smart.Components
{
public partial class ProjectsList
{
#region Public Properties
[Parameter]
public bool EnableAdmin { get; set; } = false;
[Parameter]
public bool EnableEdit { get; set; } = false;
[Parameter]
public string TextCss { get; set; } = "text-dark";
private bool isLoading { get; set; } = false;
[Parameter]
public List<TimbratureModel> ListTimb
{
get
{
return _ListTimb.OrderByDescending(x => x.DataOra).ToList();
}
set
{
_ListTimb = value;
}
}
private bool canDelete(TimbratureModel currRec)
{
bool answ = false;
if (currRec.Approv != null)
{
answ = !(bool)currRec.Approv;
}
return answ;
}
[Parameter]
public EventCallback<bool> ReqUpdate { get; set; }
#endregion Public Properties
#region Protected Methods
protected async void ApprovaTimb(TimbratureModel currRecord)
{
string message = "Sicuro di voler approvare la richiesta selezionata?";
if (!await JSRuntime.InvokeAsync<bool>("confirm", message))
return;
isLoading = true;
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
currRecord.Approv = true;
// aggiorno
await CDService.TimbratureUpdate(currRecord);
await Task.Delay(1);
isLoading = false;
await ReqUpdate.InvokeAsync(true);
}
protected async void Delete(TimbratureModel currRecord)
{
string message = "Sicuro di voler eliminare/rifiutare la richiesta selezionata?";
if (!await JSRuntime.InvokeAsync<bool>("confirm", message))
return;
isLoading = true;
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
// elimino
await CDService.TimbratureDelete(currRecord);
await Task.Delay(1);
isLoading = false;
await ReqUpdate.InvokeAsync(true);
}
protected async void ScambioInOut(TimbratureModel currRecord)
{
isLoading = true;
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
currRecord.Entrata = !currRecord.Entrata;
// aggiorno
await CDService.TimbratureUpdate(currRecord);
await Task.Delay(1);
isLoading = false;
await ReqUpdate.InvokeAsync(false);
}
#endregion Protected Methods
#region Private Properties
private List<TimbratureModel> _ListTimb { get; set; } = new List<TimbratureModel>();
[Inject]
private CoreSmartDataService CDService { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
#endregion Private Properties
}
}