diff --git a/MP.Data/Controllers/MpInveController.cs b/MP.Data/Controllers/MpInveController.cs
index cae8eef3..78f7ff7f 100644
--- a/MP.Data/Controllers/MpInveController.cs
+++ b/MP.Data/Controllers/MpInveController.cs
@@ -54,32 +54,46 @@ namespace MP.Data.Controllers
/// ///
/// ///
///
- public List ElencoOperatori(int matrOpr, string authKey)
+ public List ElencoOperatori()
{
List dbResult = new List();
using (var dbCtx = new MoonProContext(_configuration))
{
- if ((matrOpr == 0) && (authKey == ""))
- {
- dbResult = dbCtx
- .DbOperatori
- .Where(s => s.MatrOpr > 0)
- .AsNoTracking()
- .OrderBy(x => x.MatrOpr)
- .ToList();
- }
- else
- {
- dbResult = dbCtx
- .DbOperatori
- .Where(s => (s.MatrOpr > 0) && (s.MatrOpr == matrOpr) && (s.authKey == authKey))
- .AsNoTracking()
- .ToList();
- }
+ dbResult = dbCtx
+ .DbOperatori
+ .Where(s => s.MatrOpr > 0)
+ .AsNoTracking()
+ .OrderBy(x => x.MatrOpr)
+ .ToList();
}
return dbResult;
}
+ ///
+ /// login operatori
+ ///
+ /// ///
+ /// ///
+ ///
+ public bool LoginOperatore(int matrOpr, string authKey)
+ {
+ List dbResult = new List();
+ bool answ = false;
+ using (var dbCtx = new MoonProContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbOperatori
+ .Where(s => (s.MatrOpr > 0) && (s.MatrOpr == matrOpr) && (s.authKey == authKey))
+ .AsNoTracking()
+ .ToList();
+ if(dbResult.Count == 1)
+ {
+ answ = true;
+ }
+ }
+ return answ;
+ }
+
#region gestione magazzini
///
diff --git a/MP.INVE/Data/MiDataService.cs b/MP.INVE/Data/MiDataService.cs
index bcd79e69..6d826b34 100644
--- a/MP.INVE/Data/MiDataService.cs
+++ b/MP.INVE/Data/MiDataService.cs
@@ -1,4 +1,5 @@
using Egw.Core;
+using Microsoft.AspNetCore.Mvc.ModelBinding;
using MP.Data.Conf;
using MP.Data.DatabaseModels;
using MP.INVE.Pages;
@@ -6,6 +7,7 @@ using Newtonsoft.Json;
using NLog;
using StackExchange.Redis;
using System.Diagnostics;
+using System.Text;
namespace MP.INVE.Data
{
@@ -143,9 +145,51 @@ namespace MP.INVE.Data
return result;
}
-
- public List ElencoOperatori(int matrOpr, string authkey)
+ public bool loginOperatore(int matrOpr, string authkey)
{
+ string source = "";
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ AnagOperatoriModel? result = new AnagOperatoriModel();
+ bool answ = false;
+ // cerco in redis...
+ RedisValue rawData = redisDb.StringGet($"{redisElencoOperatori}:{matrOpr}:{authkey}");
+ if (!string.IsNullOrEmpty($"{rawData}"))
+ {
+
+ result = JsonConvert.DeserializeObject($"{rawData}");
+ if (result != null)
+ {
+ answ = true;
+ source = "REDIS";
+ }
+ }
+ else
+ {
+ answ = dbController.LoginOperatore(matrOpr, authkey);
+ if (answ)
+ {
+ result = ElencoOperatori().Where(x => (x.MatrOpr == matrOpr) && (x.authKey == authkey)).SingleOrDefault();
+ }
+ // serializzo e salvo...
+ rawData = JsonConvert.SerializeObject(result);
+ redisDb.StringSetAsync(redisOperatoreLogged, rawData, getRandTOut(redisLongTimeCache));
+ source = "DB";
+
+ }
+ if (result == null)
+ {
+ result = new AnagOperatoriModel();
+ }
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"loginOperatore Read from {source}: {ts.TotalMilliseconds}ms");
+ return answ;
+ }
+
+ public List ElencoOperatori()
+ {
+ string source = "";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
List? result = new List();
@@ -153,36 +197,25 @@ namespace MP.INVE.Data
RedisValue rawData = redisDb.StringGet(redisElencoOperatori);
if (!string.IsNullOrEmpty($"{rawData}"))
{
- var dese = JsonConvert.DeserializeObject>($"{rawData}");
- if (dese != null)
- {
- if ((matrOpr != 0) && (authkey != ""))
- {
- result = dese.Where(x => (x.MatrOpr == matrOpr) && (x.authKey == authkey)).ToList();
- }
- else
- {
- result = dese;
- }
- }
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ElencoOperatori Read from REDIS: {ts.TotalMilliseconds}ms");
+ result = JsonConvert.DeserializeObject>($"{rawData}");
+
+ source = "REDIS";
}
else
{
- result = dbController.ElencoOperatori(matrOpr, authkey);
+ result = dbController.ElencoOperatori();
// serializzo e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSetAsync(redisElencoOperatori, rawData, getRandTOut(redisLongTimeCache));
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- Log.Debug($"ElencoOperatori Read from DB: {ts.TotalMilliseconds}ms");
+ source = "DB";
}
if (result == null)
{
result = new List();
}
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"ElencoOperatori Read from {source}: {ts.TotalMilliseconds}ms");
return result;
}
@@ -356,7 +389,9 @@ namespace MP.INVE.Data
private const string redisBaseAddr = "MP:INVE";
private const string redisSessionBaseAddr = ":Session:";
- private const string redisElencoOperatori = redisBaseAddr + ":ListOperatori";
+ private const string redisOperatoriBaseAddr = ":Operatore:";
+ private const string redisElencoOperatori = redisBaseAddr + redisOperatoriBaseAddr + ":ListOperatori";
+ private const string redisOperatoreLogged = redisBaseAddr + redisOperatoriBaseAddr + ":OperatoreLogged";
private const string redisSessionCurrList = redisBaseAddr + redisSessionBaseAddr + ":ListSessHist";
private const string redisSessionHistList = redisBaseAddr + redisSessionBaseAddr + ":ListSessCurr";
private const string redisMagList = redisBaseAddr + ":ListMag";
diff --git a/MP.INVE/Pages/Jumper.razor.cs b/MP.INVE/Pages/Jumper.razor.cs
index b1a6cdfb..bab174dd 100644
--- a/MP.INVE/Pages/Jumper.razor.cs
+++ b/MP.INVE/Pages/Jumper.razor.cs
@@ -32,10 +32,9 @@ namespace MP.INVE.Pages
[Inject]
protected MiDataService MIService { get; set; } = null!;
- private string logged { get; set; } = "";
+ private bool logged { get; set; } = false;
private List operatore = new List();
- private AnagOperatoriModel currOperatore = new AnagOperatoriModel();
protected string idOPeratore { get; set; } = null!;
protected string authKey { get; set; } = null!;
protected override async Task OnInitializedAsync()
@@ -47,22 +46,32 @@ namespace MP.INVE.Pages
idOPeratore = _matrOpr;
authKey = _authKey;
}
+ string pw = MIService.DeriptData(authKey);
+ logged = MIService.loginOperatore(int.Parse(idOPeratore), pw);
- operatore = MIService.ElencoOperatori(int.Parse(idOPeratore), MIService.DeriptData(authKey));
-
-
- if (operatore != null)
+ if (logged)
{
- if (operatore.Count == 1)
+ if (operatore != null)
{
- logged = "success";
- NavManager.NavigateTo("Acquisizione");
- localStorage.SetItemAsync("MatrOpr", idOPeratore);
- localStorage.SetItemAsync("authKey", authKey);
- }
- else
- {
- logged = "not success";
+ AnagOperatoriModel? currOpr = operatore.Where(x => (x.MatrOpr == int.Parse(idOPeratore)) && (x.authKey == authKey)).SingleOrDefault();
+
+ if (currOpr != null)
+ {
+
+ string hash = MIService.EncriptData(currOpr.authKey);
+ OperatoreDTO sessionOpr = new OperatoreDTO
+ {
+ MatrOpr = currOpr.MatrOpr,
+ Nome = currOpr.Nome,
+ Cognome = currOpr.Cognome,
+ hashAuthKey = hash
+ };
+ if (operatore.Count == 1)
+ {
+ NavManager.NavigateTo("Acquisizione");
+ await localStorage.SetItemAsync("MatrOpr", currOpr);
+ }
+ }
}
}
}
diff --git a/MP.INVE/Pages/OperatoreLogin.razor.cs b/MP.INVE/Pages/OperatoreLogin.razor.cs
index adda95e2..7b583cbd 100644
--- a/MP.INVE/Pages/OperatoreLogin.razor.cs
+++ b/MP.INVE/Pages/OperatoreLogin.razor.cs
@@ -35,6 +35,7 @@ namespace MP.INVE.Pages
private int idOperatore { get; set; } = 0;
private string authKey { get; set; } = "";
+ private bool logged { get; set; } = false;
private List? elencoOperatori;
@@ -42,37 +43,30 @@ namespace MP.INVE.Pages
{
//await FilterChanged.InvokeAsync(actFilter);
await Task.Delay(1);
- elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey);
+ elencoOperatori = MIDataservice.ElencoOperatori();
}
private void login()
{
- elencoOperatori = MIDataservice.ElencoOperatori(idOperatore, authKey);
+ logged = MIDataservice.loginOperatore(idOperatore, authKey);
- AnagOperatoriModel? currOpr = elencoOperatori.SingleOrDefault();
+ AnagOperatoriModel? currOpr = elencoOperatori.Where(x => (x.MatrOpr == idOperatore) && (x.authKey == authKey)).SingleOrDefault();
-
- if (currOpr != null)
+ if (logged)
{
- string hash = MIDataservice.EncriptData(currOpr.authKey);
- OperatoreDTO sessionOpr = new OperatoreDTO
- {
- MatrOpr = currOpr.MatrOpr,
- Nome = currOpr.Nome,
- Cognome = currOpr.Cognome,
- hashAuthKey = hash
- };
-
-
- if (elencoOperatori.Count == 1)
+ if (currOpr != null)
{
+ string hash = MIDataservice.EncriptData(currOpr.authKey);
+ OperatoreDTO sessionOpr = new OperatoreDTO
+ {
+ MatrOpr = currOpr.MatrOpr,
+ Nome = currOpr.Nome,
+ Cognome = currOpr.Cognome,
+ hashAuthKey = hash
+ };
NavManager.NavigateTo("InveSession", true);
localStorage.SetItemAsync("MatrOpr", sessionOpr);
}
- else
- {
-
- }
}
}
}