@using CORE.Data.DbModels
@using UI.Data
@inject GpwDataService GDataServ
@inject MessageService AppMServ
@if (EnableAction)
{
}
else
{
}
@code {
[Parameter]
public DateTime InizioPer { get; set; } = DateTime.Today.AddHours(8);
[Parameter]
public int IdxDip { get; set; } = 0;
[Parameter]
public EventCallback NewItemCreated { get; set; }
[Parameter]
public bool EnableAction { get; set; } = true;
protected bool canPaste
{
get => AppMServ.clonedRA != null;
}
///
/// Indico item selezionato
///
protected async void AddNew()
{
RegAttivitaModel newItem = new RegAttivitaModel();
TimeSpan durata = new TimeSpan(1, 0, 0);
// se ho un record clonato parto da quello...
if (AppMServ.clonedRA != null && (!GDataServ.VetoInsert || (AppMServ.clonedRA.FasiNav!=null && AppMServ.clonedRA.FasiNav.Attivo)))
{
newItem = AppMServ.clonedRA;
}
else
{
// recupero ultima fase x utente...
newItem = await GDataServ.RegAttLastByDip(AppMServ.IdxDipendente, GDataServ.VetoInsert);
}
// calcolo durata arrotondata ai 5 minuti...
durata = CORE.Data.Utils.TSpanRounded(newItem.Durata, 5, false);
newItem.IdxRa = 0;
newItem.Inizio = InizioPer;
newItem.Fine = InizioPer.AddMinutes(durata.TotalMinutes);
// salvo in AppMS
AppMServ.recordRA = newItem;
await NewItemCreated.InvokeAsync(newItem);
}
}