Files
gpw_next/GPW.CORE.SMART/Components/ProjectsList.razor.cs
T
2023-01-18 08:45:56 +01:00

144 lines
4.0 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 EventCallback<RegAttivitaModel> ItemCloned { get; set; }
[Parameter]
public EventCallback<RegAttivitaModel> ItemDeleted { get; set; }
[Parameter]
public EventCallback<RegAttivitaModel> ItemSelected { get; set; }
[Parameter]
public List<RegAttivitaModel>? ListRA { get; set; } = null!;
[Parameter]
public EventCallback<bool> ReqUpdate { get; set; }
[Parameter]
public string TextCss { get; set; } = "text-dark";
#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);
}
/// <summary> Gestione evento cloning
protected async void DoClone(RegAttivitaModel currRecord)
{
if (currRecord != null)
{
await ItemCloned.InvokeAsync(currRecord);
}
}
private bool hasClonedRa
{
get => MService.clonedRA != null;
}
/// <summary>
/// Gestione evento selezione x editing
/// </summary>
protected async void DoSel(RegAttivitaModel currRecord)
{
if (currRecord != null)
{
await ItemSelected.InvokeAsync(currRecord);
}
}
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<List<RegAttivitaModel>?> _ListRA { get; set; } = new List<List<RegAttivitaModel>?>();
[Inject]
private CoreSmartDataService CDService { get; set; } = null!;
private bool isLoading { get; set; } = false;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
private MessageService MService { get; set; } = null!;
#endregion Private Properties
#region Private Methods
private bool canDelete(TimbratureModel currRec)
{
bool answ = false;
if (currRec.Approv != null)
{
answ = !(bool)currRec.Approv;
}
return answ;
}
#endregion Private Methods
}
}