@using CORE.Data.DbModels
@using UI.Data
@inject GpwDataService GDataServ
@inject MessageService AppMServ
@code {
[Parameter]
public DateTime InizioPer { get; set; } = DateTime.Today.AddHours(8);
[Parameter]
public int IdxDip { get; set; } = 0;
[Parameter]
public EventCallback NewItemCreated { get; set; }
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)
{
newItem = AppMServ.clonedRA;
}
else
{
// recupero ultima fase x utente...
newItem = await GDataServ.RegAttLastByDip(AppMServ.IdxDipendente);
}
// calcolo durata arrotondata ai 5 minuti...
#if false
TimeOnly step = new TimeOnly(0, 5);
long ticks = (newItem.Durata.Ticks + step.Ticks - 1) / step.Ticks;
durata = new TimeSpan(ticks * step.Ticks);
#endif
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);
}
}