using LiMan.DB.DBModels; using LiMan.UI.Data; using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LiMan.UI.Components { public partial class StatsCallList { #region Public Methods public string checkSelect(StatsCallModel testRec) { string answ = ""; if (currRecord != null) { try { answ = (currRecord.CodInst == testRec.CodInst && currRecord.YearRef == testRec.YearRef) ? "table-info" : ""; } catch { } } return answ; } #endregion Public Methods #region Protected Fields protected int totalCount = 0; #endregion Protected Fields #region Protected Properties [Inject] protected MessageService AppMService { get; set; } [Inject] protected LiManDataService DataService { get; set; } #endregion Protected Properties #region Protected Methods protected override async Task OnInitializedAsync() { await ReloadAllData(); } protected async Task SetNumRec(int newNum) { numRecord = newNum; await ReloadAllData(); isLoading = false; } protected async Task SetNumPage(int newNum) { currPage = newNum; await ReloadAllData(); isLoading = false; } protected async Task ResetData() { await FullReload(); } protected void Select(StatsCallModel selRecord) { currRecord = selRecord; } protected async Task UpdateData() { await FullReload(); } #endregion Protected Methods #region Private Fields private StatsCallModel currRecord = null; private DateTime dtFrom = DateTime.Today.AddMonths(-12); private DateTime dtTo = DateTime.Today.AddDays(1); private List ListRecords; private List SearchRecords; private string searchVal = ""; #endregion Private Fields #region Private Properties private int currPage { get { return AppMService.PageNum; } set { AppMService.PageNum = value; } } private DateTime DtFrom { get => dtFrom; set { if (dtFrom != value) { dtFrom = value; ForceReload(); } } } private DateTime DtTo { get => dtTo; set { if (dtTo != value) { dtTo = value; ForceReload(); } } } private bool isLoading { get; set; } = false; private int numRecord { get { return AppMService.PageSize; } set { AppMService.PageSize = value; } } #endregion Private Properties #region Private Methods private void ForceReload() { var pUpd = Task.Run(async () => { await FullReload(); }); pUpd.Wait(); } private async Task FullReload() { currRecord = null; await DataService.FlushRedisCache(); await ReloadAllData(); } private async Task ReloadAllData() { isLoading = true; await Task.Delay(1); //SearchRecords = null; SearchRecords = await DataService.StatsLogCallGetFilt(dtFrom, dtTo, searchVal); totalCount = SearchRecords.Count(); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } #endregion Private Methods } }