using Liman.CadCam.DbModel; using Liman.CadCam.Services; using Microsoft.AspNetCore.Components; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LiMan.UI.Components { public partial class CadCamSearchKey { #region Public Properties [Parameter] public string searchVal { get; set; } = ""; #endregion Public Properties #region Protected Properties [Inject] protected CadCamService CCService { get; set; } = null!; #endregion Protected Properties #region Private Properties private List AllRecords { get; set; } = new List(); private int currPage { get; set; } = 1; private bool isLoading { get; set; } = false; private List ListRecords { get; set; } = new List(); private int numRecord { get; set; } = 5; private List SearchRecords { get; set; } = new List(); private int totalCount { get; set; } = 0; #endregion Private Properties #region Protected Methods protected override async Task OnInitializedAsync() { await ReloadData(); } protected override void OnParametersSet() { ReloadAllData(); // aggiorno } protected void setNumPage(int newNum) { currPage = newNum; ReloadAllData(); isLoading = false; } protected void setNumRec(int newNum) { numRecord = newNum; ReloadAllData(); isLoading = false; } #endregion Protected Methods #region Private Methods private void ReloadAllData() { // rileggo i dati isLoading = true; if (!string.IsNullOrEmpty(searchVal)) { SearchRecords = AllRecords .Where(x => (!string.IsNullOrEmpty(x.Note) && x.Note.Contains(searchVal, StringComparison.CurrentCultureIgnoreCase)) || x.Number.ToString().Contains(searchVal, StringComparison.CurrentCultureIgnoreCase) || (!string.IsNullOrEmpty(x.Seriale) && x.Seriale.Contains(searchVal, StringComparison.CurrentCultureIgnoreCase))) .ToList(); } else { SearchRecords = new List(); } totalCount = SearchRecords.Count; // paginazione! ListRecords = SearchRecords .Skip((currPage - 1) * numRecord) .Take(numRecord) .ToList(); isLoading = false; } private async Task ReloadData() { isLoading = true; AllRecords = await CCService.KeysGetAll(); isLoading = false; } #endregion Private Methods } }