Preparazione metodi Async pre conversione FusionCache

This commit is contained in:
Samuele Locatelli
2026-05-27 19:28:13 +02:00
parent d8bc1379be
commit 2fce840ed9
12 changed files with 90 additions and 63 deletions
+22 -2
View File
@@ -871,9 +871,9 @@ namespace MP.Data.Controllers
/// Elenco valori link (x home e navMenu laterale)
/// </summary>
/// <returns></returns>
public List<LinkMenuModel> ElencoLink()
public Task<List<LinkMenuModel>> ElencoLinkAsync()
{
return ListLinkFilt("SpecLink");
return ListLinkFiltAsync("SpecLink");
}
/// <summary>
@@ -1412,6 +1412,26 @@ namespace MP.Data.Controllers
return dbResult;
}
/// <summary>
/// Elenco link JQM dato filtro tipo, Async
/// </summary>
/// <param name="tipoLink"></param>
/// <returns></returns>
public async Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink)
{
List<LinkMenuModel> dbResult = new List<LinkMenuModel>();
using (var dbCtx = new MoonProContext(options))
{
dbResult = await dbCtx
.DbSetLinkMenu
.Where(x => x.TipoLink == tipoLink)
.AsNoTracking()
.OrderBy(x => x.Ordine)
.ToListAsync();
}
return dbResult;
}
/// <summary>
/// Elenco ODL filtrati x stato, articolo, KeyRich (che contiene stato)
/// </summary>
+2 -3
View File
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Mvc.RazorPages;
using MP.SPEC.Data;
namespace MP.SPEC.Components.Layout
@@ -62,9 +61,9 @@ namespace MP.SPEC.Components.Layout
return MsgService.HasRole(Ruolo);
}
protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
ElencoLink = MDService.ElencoLink();
ElencoLink = await MDService.ElencoLinkAsync();
MService.EA_PageUpdated += OnPageUpdate;
}
+2 -2
View File
@@ -11,7 +11,7 @@ else
<div class="row">
@if (showKitDetail)
{
<MP.SPEC.Components.ProdKit.KitDetailModal ListTK="@ListKitTemplate" EC_Close="() => KitToggleDetail(null)"></MP.SPEC.Components.ProdKit.KitDetailModal>
<MP.SPEC.Components.ProdKit.KitDetailModal ListTK="@ListKitTemplate" EC_Close="() => KitToggleDetailAsync(null)"></MP.SPEC.Components.ProdKit.KitDetailModal>
}
@if (currRecord != null && !showStats && isCurrOdl)
{
@@ -109,7 +109,7 @@ else
@record.CodArticolo
@if (CheckIsKit(record.CodArticolo))
{
<button class="mx-1 btn btn-sm btn-outline-dark small" @onclick="() => KitToggleDetail(record.CodArticolo)" title="Mostra dettaglio"><i class="fa-solid fa-search"></i></button>
<button class="mx-1 btn btn-sm btn-outline-dark small" @onclick="() => KitToggleDetailAsync(record.CodArticolo)" title="Mostra dettaglio"><i class="fa-solid fa-search"></i></button>
}
</div>
<div class="small textConsensed text-secondary">@record.DescArticolo</div>
+2 -2
View File
@@ -191,11 +191,11 @@ namespace MP.SPEC.Components
return answ;
}
protected void KitToggleDetail(string? selCodArt)
protected async Task KitToggleDetailAsync(string? selCodArt)
{
if (!string.IsNullOrEmpty(selCodArt))
{
ListKitTemplate = MDService.TemplateKitFilt(selCodArt, "");
ListKitTemplate = await MDService.TemplateKitFiltAsync(selCodArt, "");
}
else
{
+2 -2
View File
@@ -16,7 +16,7 @@ else
<div class="@mainCss">
@if (showKitDetail)
{
<KitDetailModal ListTK="@ListKitTemplate" ListPODL="@ListPOdlKit" EC_Close="() => KitToggleDetail(null)"></KitDetailModal>
<KitDetailModal ListTK="@ListKitTemplate" ListPODL="@ListPOdlKit" EC_Close="() => KitToggleDetailAsync(null)"></KitDetailModal>
}
<table class="table table-sm table-striped">
<thead>
@@ -143,7 +143,7 @@ else
@record.CodArticolo
@if (CheckIsKit(record.CodArticolo))
{
<button class="mx-1 btn btn-sm btn-outline-dark small" @onclick="() => KitToggleDetail(record)" title="Mostra dettaglio KIT"><i class="fa-solid fa-search"></i></button>
<button class="mx-1 btn btn-sm btn-outline-dark small" @onclick="() => KitToggleDetailAsync(record)" title="Mostra dettaglio KIT"><i class="fa-solid fa-search"></i></button>
}
</div>
<div class="small textConsensed text-secondary">@record.DescArticolo</div>
+2 -2
View File
@@ -151,11 +151,11 @@ namespace MP.SPEC.Components
await RecordEdit.InvokeAsync(selRec);
}
protected void KitToggleDetail(PODLExpModel? recSel)
protected async Task KitToggleDetailAsync(PODLExpModel? recSel)
{
if (recSel != null)
{
ListKitTemplate = MDService.TemplateKitFilt(recSel.CodArticolo, "");
ListKitTemplate = await MDService.TemplateKitFiltAsync(recSel.CodArticolo, "");
ListPOdlKit = MDService.POdlListByKitParent(recSel.IdxPromessa);
}
else
+2 -2
View File
@@ -16,7 +16,7 @@
{
@if (doShowDetail)
{
<KitDetailModal ListTK="@ListKitTemplate" ListPODL="@ListRecKitPODL" EC_Close="() => KitToggleDetail(null)"></KitDetailModal>
<KitDetailModal ListTK="@ListKitTemplate" ListPODL="@ListRecKitPODL" EC_Close="() => KitToggleDetailAsync(null)"></KitDetailModal>
}
<table class="table table-sm table-striped">
<thead>
@@ -33,7 +33,7 @@
{
<tr>
<td>
<button class="btn btn-sm btn-info" @onclick="() => KitToggleDetail(record)" title="Mostra dettaglio"><i class="fa-solid fa-search"></i></button>
<button class="btn btn-sm btn-info" @onclick="() => KitToggleDetailAsync(record)" title="Mostra dettaglio"><i class="fa-solid fa-search"></i></button>
</td>
<td>@record.CodArtParent</td>
<td>@record.ChildFound / @numRecWsm</td>
@@ -41,17 +41,17 @@ namespace MP.SPEC.Components.ProdKit
#region Protected Methods
protected void KitToggleDetail(TksScoreModel? currRec)
protected async Task KitToggleDetailAsync(TksScoreModel? currRec)
{
CodArtParent = currRec != null ? currRec.CodArtParent : "";
if (!string.IsNullOrEmpty(CodArtParent))
{
ListKitTemplate = MDService.TemplateKitFilt(CodArtParent, "");
ListKitTemplate = await MDService.TemplateKitFiltAsync(CodArtParent, "");
totalKitCount = ListKitTemplate.Count;
ListRecKitPODL = PodlRecords
.Where(x => !string.IsNullOrEmpty(x.KeyRichiesta)
.Where(x => !string.IsNullOrEmpty(x.KeyRichiesta)
&& x.KeyRichiesta.StartsWith("KIT")
&& x.CodArticolo==CodArtParent)
&& x.CodArticolo == CodArtParent)
.ToList();
}
else
+9 -9
View File
@@ -838,14 +838,14 @@ namespace MP.SPEC.Data
/// Elenco link validi
/// </summary>
/// <returns></returns>
public List<LinkMenuModel> ElencoLink()
public async Task<List<LinkMenuModel>> ElencoLinkAsync()
{
using var activity = ActivitySource.StartActivity("ElencoLink");
using var activity = ActivitySource.StartActivity("ElencoLinkAsync");
string source = "DB";
var linkList = dbController.ElencoLink();
var linkList = await dbController.ElencoLinkAsync();
activity?.SetTag("data.source", source);
activity?.Stop();
LogTrace($"ElencoLink | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
LogTrace($"ElencoLinkAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
return linkList;
}
@@ -2773,14 +2773,14 @@ namespace MP.SPEC.Data
/// <param name="codParent"></param>
/// <param name="codChild"></param>
/// <returns></returns>
public List<TemplateKitModel> TemplateKitFilt(string codParent, string codChild)
public async Task<List<TemplateKitModel>> TemplateKitFiltAsync(string codParent, string codChild)
{
using var activity = ActivitySource.StartActivity("TemplateKitFilt");
using var activity = ActivitySource.StartActivity("TemplateKitFiltAsync");
string source = "DB";
List<TemplateKitModel>? result = new List<TemplateKitModel>();
// cerco in redis...
string currKey = $"{Utils.redisKitTempl}:{codParent}:{codChild}";
RedisValue rawData = redisDb.StringGet(currKey);
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<TemplateKitModel>>($"{rawData}");
@@ -2791,7 +2791,7 @@ namespace MP.SPEC.Data
result = dbController.TemplateKitFilt(codParent, codChild);
// serializzo e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, TimeSpan.FromMinutes(redisLongTimeCache));
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromMinutes(redisLongTimeCache));
}
if (result == null)
{
@@ -2800,7 +2800,7 @@ namespace MP.SPEC.Data
activity?.SetTag("data.source", source);
activity?.SetTag("result.count", result.Count);
activity?.Stop();
LogTrace($"TemplateKitFilt | {source} | {activity?.Duration.TotalMilliseconds}ms");
LogTrace($"TemplateKitFiltAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
return result;
}
+1 -2
View File
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using MP.AppAuth.Models;
using MP.Data.DbModels;
using MP.SPEC.Data;
@@ -38,7 +37,7 @@ namespace MP.SPEC.Pages
protected override async Task OnInitializedAsync()
{
// recupero elenco link
ElencoLink = MDService.ElencoLink();
ElencoLink = await MDService.ElencoLinkAsync();
currAzienda = await MDService.ConfigTryGetAsync("AZIENDA");
await Task.Delay(1);
}
+2 -2
View File
@@ -29,12 +29,12 @@
}
<div class="input-group me-2" style="min-width: 20rem;">
<span class="input-group-text"><i class="fa fa-search"></i></span>
<input type="text" class="form-control" placeholder="@($"Parent {minChar}+ | Ctrl-R")" aria-label="Ricerca" title="@($"Ricerca Parent | {minChar}+ | Ctrl-R")" @bind="@SearchParent" accesskey="R">
<input type="text" class="form-control" placeholder="@($"Parent {minChar}+ | Ctrl-R")" aria-label="Ricerca" title="@($"Ricerca Parent | {minChar}+ | Ctrl-R")" @bind="@SearchParent" @bind:after="ResetDataAsync" accesskey="R">
<button class="btn @sParentCss" @onclick="() => ResetParent()"><i class="fa fa-ban"></i></button>
</div>
<div class="input-group" style="min-width: 20rem;">
<span class="input-group-text"><i class="fa fa-search"></i></span>
<input type="text" class="form-control" placeholder="@($"Child {minChar}+ | Ctrl-R")" aria-label="Ricerca" title="@($"Ricerca Child | {minChar}+ | Ctrl-T")" @bind="@SearchChild" accesskey="T">
<input type="text" class="form-control" placeholder="@($"Child {minChar}+ | Ctrl-R")" aria-label="Ricerca" title="@($"Ricerca Child | {minChar}+ | Ctrl-T")" @bind="@SearchChild" @bind:after="ResetDataAsync" accesskey="T">
<button class="btn @sChildCss" @onclick="() => ResetChild()"><i class="fa fa-ban"></i></button>
</div>
</div>
+40 -31
View File
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.JSInterop;
using MP.Data.DbModels;
using MP.SPEC.Data;
@@ -56,9 +55,6 @@ namespace MP.SPEC.Pages
if (sCodChild != value)
{
sCodChild = value;
currPage = 1;
ListRecords = null;
ReloadData();
}
}
}
@@ -75,9 +71,6 @@ namespace MP.SPEC.Pages
if (sCodParent != value)
{
sCodParent = value;
currPage = 1;
ListRecords = null;
ReloadData();
}
}
}
@@ -142,8 +135,7 @@ namespace MP.SPEC.Pages
protected async Task DoCancel()
{
EditRecord = null;
ReloadData();
await Task.Delay(1);
await ResetDataAsync();
}
protected async Task DoClone(TemplateKitModel selRec)
@@ -170,11 +162,9 @@ namespace MP.SPEC.Pages
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Eliminazione riga KIT: sei sicuro di voler procedere?"))
return;
await Task.Delay(1);
var done = await MDService.TemplateKitDelete(selRec);
EditRecord = null;
ReloadData();
await Task.Delay(1);
await ResetDataAsync();
}
/// <summary>
@@ -203,8 +193,7 @@ namespace MP.SPEC.Pages
await Task.Delay(1);
var done = await MDService.TemplateKitUpsert(selRec, CodAzienda);
EditRecord = null;
ReloadData();
await Task.Delay(1);
await ResetDataAsync();
}
protected override void OnInitialized()
@@ -237,15 +226,15 @@ namespace MP.SPEC.Pages
}
}
protected override void OnParametersSet()
protected override Task OnParametersSetAsync()
{
ReloadData();
return ReloadDataAsync();
}
protected void ResetChild()
protected async Task ResetChild()
{
SearchChild = "";
ReloadData();
await ReloadDataAsync();
}
protected void ResetData()
@@ -253,10 +242,10 @@ namespace MP.SPEC.Pages
EditRecord = null;
}
protected void ResetParent()
protected async Task ResetParent()
{
SearchParent = "";
ReloadData();
await ReloadDataAsync();
}
protected void ResetSel()
@@ -280,10 +269,10 @@ namespace MP.SPEC.Pages
numRecord = newNum;
}
protected void UpdateData()
protected async Task UpdateData()
{
EditRecord = null;
ReloadData();
await ReloadDataAsync();
}
#endregion Protected Methods
@@ -305,6 +294,7 @@ namespace MP.SPEC.Pages
private bool enabKitCount = false;
private bool enabKitSearch = false;
private List<TemplateKitModel>? ListRecords;
private int minChar = 2;
@@ -329,7 +319,7 @@ namespace MP.SPEC.Pages
if (_currPage != value)
{
_currPage = value;
ReloadData();
UpdateTable();
}
}
}
@@ -344,7 +334,7 @@ namespace MP.SPEC.Pages
if (_numRecord != value)
{
_numRecord = value;
ReloadData();
UpdateTable();
}
}
}
@@ -357,18 +347,25 @@ namespace MP.SPEC.Pages
#region Private Methods
private void ReloadData()
/// <summary>
/// reeload dati + paginazione
/// </summary>
/// <returns></returns>
private async Task ReloadDataAsync()
{
isLoading = true;
SearchRecords = MDService.TemplateKitFilt(SearchParent, SearchChild);
SearchRecords = await MDService.TemplateKitFiltAsync(SearchParent, SearchChild);
totalCount = SearchRecords.Count;
// conto i kit = distinct...
kitCount = SearchRecords.GroupBy(x => x.CodArtParent).Count();
ListRecords = SearchRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
UpdateTable();
}
private Task ResetDataAsync()
{
currPage = 1;
ListRecords = null;
return ReloadDataAsync();
}
/// <summary>
@@ -392,6 +389,18 @@ namespace MP.SPEC.Pages
}
}
/// <summary>
/// Paginazione dati
/// </summary>
private void UpdateTable()
{
ListRecords = SearchRecords?
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList() ?? new();
isLoading = false;
}
#endregion Private Methods
}
}