Files
GPW/GPW.CORE.UI/Components/RegAttEditor.razor.cs
T
Samuele Locatelli bb5d8271a1 Ok clona + insert!
2022-01-04 15:27:55 +01:00

161 lines
4.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using GPW.CORE.UI;
using GPW.CORE.UI.Shared;
using GPW.CORE.Data.DbModels;
using GPW.CORE.UI.Data;
namespace GPW.CORE.UI.Components
{
public partial class RegAttEditor
{
protected List<AnagGruppiModel> gruppiList { get; set; } = new List<AnagGruppiModel>();
protected List<AnagProgettiModel> projList { get; set; } = new List<AnagProgettiModel>();
protected List<AnagFasiModel> fasiList { get; set; } = new List<AnagFasiModel>();
protected bool vetoUpd = false;
protected string _gruppoSel = "";
protected int _idxProj = 0;
public string gruppoSel
{
get
{
return _gruppoSel;
}
set
{
_gruppoSel = value;
if (!vetoUpd)
{
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
public int idxProj
{
get
{
return _idxProj;
}
set
{
_idxProj = value;
if (!vetoUpd)
{
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
[Inject]
private IJSRuntime JSRuntime { get; set; }
[Inject]
private MessageService AppMServ { get; set; }
[Parameter]
public RegAttivitaModel currRecord
{
get
{
return AppMServ.recordRA;
}
set
{
AppMServ.recordRA = value;
vetoUpd = true;
if (value.FasiNav != null && value.FasiNav.ProgettoNav != null)
{
gruppoSel = value.FasiNav.ProgettoNav.Gruppo;
idxProj = value.FasiNav.IdxProgetto != null ? (int)value.FasiNav.IdxProgetto : 0;
}
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
vetoUpd = false;
}
}
[Parameter]
public EventCallback<bool> ItemReset { get; set; }
[Parameter]
public EventCallback<bool> ItemUpdated { get; set; }
[Inject]
protected GpwDataService GDataServ { get; set; }
protected async Task ReloadData()
{
gruppiList = await GDataServ.AnagGruppiAll();
var allProj = await GDataServ.AnagProjAll();
projList = allProj
.Where(x => x.Attivo == true && x.Gruppo == gruppoSel)
.OrderBy(x => x.ClienteNav.RagSociale)
.ThenBy(x => x.NomeProj)
.ToList();
var allFasi = await GDataServ.AnagFasiAll();
fasiList = allFasi
.Where(x => x.IdxProgetto == idxProj)
.ToList();
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void DoReset()
{
await ItemReset.InvokeAsync(true);
}
/// <summary>
/// Aggiorno e riporto update
/// </summary>
protected async void DoUpdate()
{
// aggiorno
await GDataServ.RegAttUpdate(currRecord);
// resetto clone e record corrente...
AppMServ.clonedRA = null;
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
/// <summary>
/// Salvo in MService record clonato
/// </summary>
protected async void DoClone()
{
AppMServ.clonedRA = currRecord;
await ItemReset.InvokeAsync(true);
}
/// <summary>
/// Elimino record
/// </summary>
protected async void DoDelete()
{
// chiedo verifica
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record selezionato??"))
return;
// aggiorno
await GDataServ.RegAttDelete(currRecord);
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
}
}