using GPW.CORE.Data.DbModels; using GPW.CORE.Data.Services; using Microsoft.AspNetCore.Components; namespace GPW.CORE.WRKLOG.Components.Compo { public partial class AddRA { #region Public Properties [Parameter] public bool EnableAction { get; set; } = true; [Parameter] public int IdxDip { get; set; } = 0; [Parameter] public DateTime InizioPer { get; set; } = DateTime.Today.AddHours(8); [Parameter] public EventCallback NewItemCreated { get; set; } #endregion Public Properties #region Protected Properties [Inject] protected MessageService AppMServ { get; set; } = null!; protected bool canPaste { get => AppMServ.clonedRA != null; } [Inject] protected GpwDataService GDataServ { get; set; } = null!; #endregion Protected Properties #region Protected Methods /// /// 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); } #endregion Protected Methods } }