using EgwCoreLib.Lux.Data; using EgwCoreLib.Lux.Data.DbModel; using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using static EgwCoreLib.Lux.Core.Enums; namespace Lux.UI.Components.Compo { public partial class OfferRowMan { #region Public Properties [Parameter] public DisplayMode DisplayMode { get; set; } = DisplayMode.Standard; [Parameter] public int OfferID { get; set; } = 0; #endregion Public Properties #region Protected Properties [Inject] protected IConfiguration Config { get; set; } = null!; [Inject] protected DataLayerServices DLService { get; set; } = null!; [Inject] protected ImageCacheService ICService { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected void DoEdit(OfferRowModel curRec) { EditRecord = curRec; } protected string imgUrl(string imgUid, string env) { // cast string su env.. EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; Enum.TryParse(env, out envir); return ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, imgUid, envir); } protected override void OnInitialized() { apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; imgBasePath = Config.GetValue("ServerConf:ImageBaseUrl") ?? ""; } protected override async Task OnParametersSetAsync() { await ReloadData(); UpdateTable(); } protected async Task RecalcOffer() { if (!await JSRuntime.InvokeAsync("confirm", $"Confermi di voler ricalcolare importi offerta?")) return; isLoading = true; await DLService.OffertUpdateCost(OfferID); await Task.Delay(50); await ReloadData(); UpdateTable(); isLoading = false; } #endregion Protected Methods #region Private Fields private List AllRecords = new List(); private string apiUrl = ""; private int currPage = 1; private OfferRowModel? EditRecord = null; private string imgBasePath = ""; private bool isLoading = false; private List ListRecords = new List(); private int numRecord = 10; private int totalCount = 0; #endregion Private Fields #region Private Methods /// /// Legge i dati dei record completi /// private async Task ReloadData() { if (OfferID > 0) { AllRecords = await DLService.OfferRowGetByOffer(OfferID); totalCount = AllRecords.Count(); } } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }