using EgwCoreLib.Lux.Core; using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; namespace Lux.UI.Components.Compo { public partial class OfferCommonPar { #region Public Properties [Parameter] public OfferModel CurrRecord { get; set; } = null!; [Parameter] public EventCallback EC_Close { get; set; } [Parameter] public EventCallback EC_Updated { get; set; } #endregion Public Properties #region Protected Properties [Inject] protected ConfigDataService CDService { get; set; } = null!; [Inject] protected IConfiguration Config { get; set; } = null!; [Inject] protected CalcRuidService CRService { get; set; } = null!; [Inject] protected CalcRequestService CService { get; set; } = null!; [Inject] protected DataLayerServices DLService { get; set; } = null!; /// /// Gestione selezione Colore /// protected string SelColor { get => CurrSel.GetVal("Color"); set => CurrSel.SetVal("Color", value); } /// /// Gestione selezione Glass /// protected string SelGlass { get => CurrSel.GetVal("Glass"); set => CurrSel.SetVal("Glass", value); } /// /// Gestione selezione Profile /// protected string SelProfile { get => CurrSel.GetVal("Profile"); set => CurrSel.SetVal("Profile", value); } /// /// Gestione selezione Wood /// protected string SelWood { get => CurrSel.GetVal("Wood"); set => CurrSel.SetVal("Wood", value); } #endregion Protected Properties #region Protected Methods protected override void OnInitialized() { ConfInit(); } protected override async Task OnParametersSetAsync() { isLoading = true; // deserializzo se possibile dal record... CurrSel = new ParamDict(CurrRecord.DictPresel); // leggo dati di base var AllColors = await DLService.GenValGetFiltAsync("WoodCol"); var AllConfGlass = await DLService.ConfGlassGetAllAsync(); var AllConfProfile = CDService.ProfileList(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "Default"); // se fosse vuoto chiamo update... if (AllConfProfile == null || AllConfProfile.Count == 0) { await callRefreshProfList(); // aspetto 200ms... e richiedo! await Task.Delay(200); AllConfProfile = CDService.ProfileList(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "Default"); } var AllConfWood = await DLService.ConfWoodGetAllAsync(); // conversione tipi ListColors = AllColors .Select(x => x.ValString) .ToList(); ListGlass = AllConfGlass .Select(x => x.Description) .ToList(); ListProfiles = AllConfProfile; ListWood = AllConfWood .Select(x => x.Description) .ToList(); isLoading = false; } #endregion Protected Methods #region Private Fields private string apiUrl = ""; private string calcTag = "calc"; private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS cEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; private ParamDict CurrSel = new ParamDict(""); private string genericBasePath = ""; private bool isLoading = false; private List ListColors = new List(); private List ListGlass = new List(); private List ListProfiles = new List(); private List ListWood = new List(); #endregion Private Fields #region Private Methods /// /// Effettua vera richiesta della BOM /// /// private async Task callRefreshProfList() { Dictionary DictExec = new Dictionary(); var cMode = Egw.Window.Data.Enums.QuestionModes.CONFIG; var cSubMode = Egw.Window.Data.Enums.QuestionConfSubModes.PROFILELIST; // compongo righiesta string reqUid = "Default"; DictExec.Add("Mode", $"{(int)cMode}"); DictExec.Add("UID", reqUid); // creo registrazione richiesta... var ruid = await CRService.AddRequestAsync($"{cEnvir}", $"{cMode}-{cSubMode}", reqUid); // aggiungo RUID effettivo DictExec.Add("RUID", ruid); DictExec.Add("SubMode", $"{(int)cSubMode}"); CalcRequestDTO req = new CalcRequestDTO() { EnvType = cEnvir, DictExec = DictExec }; // chiamo la chiamata POST alla API, che manda la richiesta via REDIS await CService.CallRestPost($"{apiUrl}/{genericBasePath}", $"{calcTag}/{reqUid}", req); } private void ConfInit() { apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; genericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; calcTag = Config.GetValue("ServerConf:CalcTag") ?? "calc"; } private async Task DoCancel() { await EC_Close.InvokeAsync(true); } private async Task DoSave() { // aggiorno valore serializzato... CurrRecord.DictPresel = CurrSel.Serialized; // richiesta update con salvataggio record await EC_Updated.InvokeAsync(CurrRecord); } #endregion Private Methods } }