using EgwCoreLib.Lux.Data.DbModel.Admin; namespace Lux.UI.Components.Compo.Admin { public partial class VocabMan { #region Public Properties [Parameter] public List AllRecord { get; set; } = null!; [Parameter] public EventCallback EC_Updated { get; set; } [Parameter] public EventCallback EC_ReqClone { get; set; } [Parameter] public EventCallback EC_ReqFilt { get; set; } [Parameter] public List ListLingue { get; set; } = null!; [Parameter] public string SearchVal { get; set; } = string.Empty; [Parameter] public string SelLingua { get; set; } = ""; #endregion Public Properties #region Protected Methods protected override void OnParametersSet() { if (AllRecord != null && AllRecord.Count > 0) { isLoading = true; UpdateTable(); } } private async Task DoClone() { if (!string.IsNullOrEmpty(SelLingua)) await EC_ReqClone.InvokeAsync(SelLingua); } #endregion Protected Methods #region Private Fields private int currPage = 1; private VocabolarioModel? editRec = null; private VocabolarioModel? currRec = null; private bool isLoading = false; private List ListPaged = new(); private int numRecord = 10; private int totalCount = 0; #endregion Private Fields #region Private Methods private void DoCancel() { currRec = null; editRec = null; } private void DoEdit(VocabolarioModel selRec) { editRec = editRec == null || editRec.Lemma != selRec.Lemma ? selRec : null; } private async Task DoSelect(VocabolarioModel selRec) { currRec = selRec; await Task.Delay(1); await EC_ReqFilt.InvokeAsync(selRec.Lemma); } private async Task DoSave() { await EC_Updated.InvokeAsync(editRec); editRec = null; } private void FiltLingua() { UpdateTable(); } private void SaveNumRec(int newNum) { numRecord = newNum; currPage = 1; UpdateTable(); } private void SavePage(int newNum) { currPage = newNum; UpdateTable(); } /// /// Filtro e paginazione /// private void UpdateTable() { ListPaged.Clear(); if (!string.IsNullOrEmpty(SelLingua)) { var rawList = AllRecord.Where(x => x.Lingua == SelLingua).ToList(); if (!string.IsNullOrEmpty(SearchVal)) { rawList = rawList.Where(x => x.Lemma.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.Traduzione.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ).ToList(); } totalCount = rawList.Count; // fix paginazione ListPaged = rawList .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); } isLoading = false; } #endregion Private Methods } }