using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MP.Stats.Data; using System; using System.Threading.Tasks; namespace MP.Stats.Pages { public partial class Controlli : ComponentBase, IDisposable { #region Private Fields private MP.Data.DatabaseModels.ResControlli currRecord = null; private MP.Data.DatabaseModels.ResControlli[] ListRecords; #endregion Private Fields #region Private Properties private int numRecord { get; set; } = 10; #endregion Private Properties #region Protected Properties [Inject] protected IJSRuntime JSRuntime { get; set; } [Inject] protected MessageService MessageService { get; set; } [Inject] protected NavigationManager NavManager { get; set; } [Inject] protected MpStatsService StatService { get; set; } #endregion Protected Properties #region Protected Methods protected async Task ForceReload(int newNum) { numRecord = newNum; ListRecords = await StatService.StatControlliGetAll(numRecord, MessageService.SearchVal); } protected override async Task OnInitializedAsync() { numRecord = 10; MessageService.ShowSearch = true; MessageService.EA_SearchUpdated += OnSeachUpdated; ListRecords = await StatService.StatControlliGetAll(numRecord, MessageService.SearchVal); } protected void ResetData() { StatService.rollBackEdit(currRecord); currRecord = null; } protected async Task UpdateData() { currRecord = null; ListRecords = await StatService.StatControlliGetAll(numRecord, MessageService.SearchVal); } #endregion Protected Methods #region Public Methods public string checkSelect(int IdxControllo) { string answ = ""; if (currRecord != null) { try { answ = (currRecord.IdxControllo == IdxControllo) ? "table-info" : ""; } catch { } } return answ; } public void Dispose() { MessageService.EA_SearchUpdated -= OnSeachUpdated; } public void OnSeachUpdated() { InvokeAsync(() => { UpdateData(); StateHasChanged(); }); } #endregion Public Methods } }