using EgwCoreLib.Razor; namespace Lux.UI.Components.Compo.Contatti { public partial class CustomerMan { #region Public Properties [Parameter] public EventCallback EC_EditReq { get; set; } [Parameter] public EventCallback EC_UpdateReq { get; set; } [Parameter] public List CustomerList { get; set; } = null!; [Parameter] public string SearchVal { get; set; } = null!; #endregion Public Properties #region Protected Methods protected override void OnParametersSet() { if (CustomerList != null && CustomerList.Count > 0) { ReloadData(); UpdateTable(); } } #endregion Protected Methods #region Private Fields private int currPage = 1; private CustomerModel? editRecord = null; private bool isLoading = false; public List ListFiltCustomer { get; set; } = null!; private List ListRecords = new List(); private List OfferList = new List(); private List OrderList = new List(); private int numRecord = 10; private CustomerModel? selRecord = null; private int totalCount = 0; private BootstrapModal Modal = new(); private string mTitle = ""; private string mMessage = ""; private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND; private Dictionary modalOpt = new Dictionary(); #endregion Private Fields #region Private Properties [Inject] private IJSRuntime JSRuntime { get; set; } = null!; [Inject] private ICustomerService CService { get; set; } = null!; #endregion Private Properties #region Private Methods private string checkSel(CustomerModel curRec) { return (selRecord != null && curRec.CustomerID == selRecord.CustomerID) ? "table-info" : ""; } /// /// Imposta record x eliminazione /// /// private async Task DoDelete(CustomerModel selRec) { mTitle = "Attenzione"; mMessage = "Sicuro di voler eliminare il record?\n "; if (string.IsNullOrEmpty(selRec.CompanyName)) { mMessage = mMessage + $"Dettagli: {selRec.FirstName} | {selRec.LastName} | {selRec.VAT}"; } else { mMessage = mMessage + $"Dettagli: {selRec.CompanyName} | {selRec.VAT}"; } mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; // esegue eliminazione del record... await CService.DeleteAsync(selRec); await EC_UpdateReq.InvokeAsync(true); } /// /// Edit cliente selezionato /// /// private Task DoEdit(CustomerModel curRec) { editRecord = curRec; selRecord = curRec; return EC_EditReq.InvokeAsync(editRecord); } /// /// Reset selezione /// private Task DoReset() { selRecord = null; editRecord = null; return EC_EditReq.InvokeAsync(editRecord); } private void ReloadData() { isLoading = true; ListFiltCustomer = CustomerList; IEnumerable query = CustomerList; if (!string.IsNullOrEmpty(SearchVal) && SearchVal.Length >= 3) { query = query.Where(x => x.FirstName.Contains(SearchVal, StringComparison.OrdinalIgnoreCase) || x.LastName.Contains(SearchVal, StringComparison.OrdinalIgnoreCase) || x.CompanyName.Contains(SearchVal, StringComparison.OrdinalIgnoreCase)); } // effettuo search ListFiltCustomer = query.ToList(); totalCount = ListFiltCustomer.Count; } private void SaveNumRec(int newNum) { numRecord = newNum; currPage = 1; UpdateTable(); } private void SavePage(int newNum) { currPage = newNum; UpdateTable(); } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = ListFiltCustomer .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }