diff --git a/MP.Data/Controllers/MpInveController.cs b/MP.Data/Controllers/MpInveController.cs
index e001a5ec..e6c65cb3 100644
--- a/MP.Data/Controllers/MpInveController.cs
+++ b/MP.Data/Controllers/MpInveController.cs
@@ -1,5 +1,4 @@
-using Microsoft.Data.SqlClient;
-using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using MP.Data.DatabaseModels;
using NLog;
@@ -24,48 +23,6 @@ namespace MP.Data.Controllers
#region Public Methods
- ///
- /// Elenco Inventari CORRENTI (=aperti, senza data fine)
- ///
- ///
- public List InventSessCurrList()
- {
- List dbResult = new List();
- using (var dbCtx = new MoonPro_InveContext(_configuration))
- {
- dbResult = dbCtx
- .DbInveSess
- .Where(x => x.DtEnd == null)
- .Include(m=>m.AnagMagNav)
- .AsNoTracking()
- .OrderByDescending(x => x.DtStart)
- .ToList();
- }
- return dbResult;
- }
-
- ///
- /// Elenco Inventari tipo Azienda (TUTTI, chiusi e paerti) filtrati x data
- ///
- ///
- ///
- ///
- public List InventSessHistList(DateTime FromDate, DateTime ToDate)
- {
- List dbResult = new List();
- using (var dbCtx = new MoonPro_InveContext(_configuration))
- {
- dbResult = dbCtx
- .DbInveSess
- .Where(x => x.DtStart >= FromDate && x.DtStart <= ToDate && x.DtEnd != null)
- .Include(m=>m.AnagMagNav)
- .AsNoTracking()
- .OrderByDescending(x => x.DtStart)
- .ToList();
- }
- return dbResult;
- }
-
public void Dispose()
{
_configuration = null;
@@ -90,23 +47,6 @@ namespace MP.Data.Controllers
}
return dbResult;
}
- ///
- /// Elenco Magazzini
- ///
- ///
- public List ElencoMagazzini()
- {
- List dbResult = new List();
- using (var dbCtx = new MoonPro_InveContext(_configuration))
- {
- dbResult = dbCtx
- .DbAnagMag
- .AsNoTracking()
- .OrderBy(x => x.MagID)
- .ToList();
- }
- return dbResult;
- }
///
/// Elenco operatori
@@ -140,11 +80,31 @@ namespace MP.Data.Controllers
return dbResult;
}
+ #region gestione magazzini
+
///
- /// insert di un record sessione
+ /// Elenco Magazzini
///
///
- public async Task InsertNewSessione(InventorySessionModel newRec)
+ public List ElencoMagazzini()
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonPro_InveContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbAnagMag
+ .AsNoTracking()
+ .OrderBy(x => x.MagID)
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// insert di un record magazzino
+ ///
+ ///
+ public async Task InsertNewMag(AnagMagModel newRec)
{
bool fatto = false;
using (var dbCtx = new MoonPro_InveContext(_configuration))
@@ -152,18 +112,48 @@ namespace MP.Data.Controllers
try
{
dbCtx
- .DbInveSess
+ .DbAnagMag
.Add(newRec);
await dbCtx.SaveChangesAsync();
fatto = true;
}
catch (Exception exc)
{
- Log.Error($"Eccezione durante InsertNewSessione{Environment.NewLine}{exc}");
+ Log.Error($"Eccezione durante InsertNewMag{Environment.NewLine}{exc}");
}
}
return fatto;
}
+
+ ///
+ /// delete magazzino
+ ///
+ ///
+ public async Task DeleteMag(AnagMagModel record)
+ {
+ bool fatto = false;
+ using (var dbCtx = new MoonPro_InveContext(_configuration))
+ {
+ try
+ {
+ dbCtx
+ .DbAnagMag
+ .Remove(record);
+ await dbCtx.SaveChangesAsync();
+ fatto = true;
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione durante deleteMag{Environment.NewLine}{exc}");
+ }
+ }
+ return fatto;
+ }
+
+ #endregion gestione magazzini
+
+ #region gestione sessione
+
///
/// delete sessione
///
@@ -188,6 +178,76 @@ namespace MP.Data.Controllers
}
return fatto;
}
+
+ ///
+ /// insert di un record sessione
+ ///
+ ///
+ public async Task InsertNewSessione(InventorySessionModel newRec)
+ {
+ bool fatto = false;
+ using (var dbCtx = new MoonPro_InveContext(_configuration))
+ {
+ try
+ {
+ dbCtx
+ .DbInveSess
+ .Add(newRec);
+ await dbCtx.SaveChangesAsync();
+ fatto = true;
+ }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione durante InsertNewSessione{Environment.NewLine}{exc}");
+ }
+ }
+ return fatto;
+ }
+
+ ///
+ /// Elenco Inventari tipo Azienda (TUTTI, chiusi e paerti) filtrati x data
+ ///
+ ///
+ ///
+ ///
+ public List InventSessHistList(DateTime FromDate, DateTime ToDate)
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonPro_InveContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbInveSess
+ .Where(x => x.DtStart >= FromDate && x.DtStart <= ToDate && x.DtEnd != null)
+ .Include(m => m.AnagMagNav)
+ .AsNoTracking()
+ .OrderByDescending(x => x.DtStart)
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ ///
+ /// Elenco Inventari CORRENTI (=aperti, senza data fine)
+ ///
+ ///
+ public List InventSessCurrList()
+ {
+ List dbResult = new List();
+ using (var dbCtx = new MoonPro_InveContext(_configuration))
+ {
+ dbResult = dbCtx
+ .DbInveSess
+ .Where(x => x.DtEnd == null)
+ .Include(m => m.AnagMagNav)
+ .AsNoTracking()
+ .OrderByDescending(x => x.DtStart)
+ .ToList();
+ }
+ return dbResult;
+ }
+
+ #endregion gestione sessione
+
#endregion Public Methods
#region Private Fields
diff --git a/MP.INVE/Data/MiDataService.cs b/MP.INVE/Data/MiDataService.cs
index d27875dd..ead59261 100644
--- a/MP.INVE/Data/MiDataService.cs
+++ b/MP.INVE/Data/MiDataService.cs
@@ -1,6 +1,7 @@
using Egw.Core;
using MP.Data.Conf;
using MP.Data.DatabaseModels;
+using MP.INVE.Pages;
using Newtonsoft.Json;
using NLog;
using StackExchange.Redis;
@@ -68,19 +69,66 @@ namespace MP.INVE.Data
public async Task InsertNewSessione(InventorySessionModel newSess)
{
+ bool result = false;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ result = await dbController.InsertNewSessione(newSess);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{redisBaseAddr}{redisSessionBaseAddr}*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"InsertNewSessione | Id sessione: {newSess.InveSessID} | Id sessione: {newSess.Description} | {ts.TotalMilliseconds}ms");
+ return result;
// aggiungo record al DB
- bool answ = await dbController.InsertNewSessione(newSess);
-
- return answ;
}
public async Task deleteSessione(InventorySessionModel session)
{
+ bool result = false;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ result = await dbController.deleteSessione(session);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{redisBaseAddr}{redisSessionBaseAddr}*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"deleteSessione | Id sessione: {session.InveSessID} | Id sessione: {session.Description} | {ts.TotalMilliseconds}ms");
+ return result;
// elimino record dal DB
- bool answ = await dbController.deleteSessione(session);
-
- return answ;
}
+ public async Task InsertNewMag(AnagMagModel newMag)
+ {
+ bool result = false;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ result = await dbController.InsertNewMag(newMag);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{redisMagList}");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"InsertNewMag | Codice magazzino: {newMag.CodMag} | Descrizione magazzino: {newMag.DescMag} | {ts.TotalMilliseconds}ms");
+ return result;
+ // aggiungo record al DB
+ }
+ public async Task DeleteMag(AnagMagModel Mag)
+ {
+ bool result = false;
+ Stopwatch stopWatch = new Stopwatch();
+ stopWatch.Start();
+ result = await dbController.DeleteMag(Mag);
+ // elimino cache redis...
+ RedisValue pattern = new RedisValue($"{redisMagList}:*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ stopWatch.Stop();
+ TimeSpan ts = stopWatch.Elapsed;
+ Log.Debug($"DeleteMag | Codice magazzino: {Mag.CodMag} | Descrizione magazzino: {Mag.DescMag} | {ts.TotalMilliseconds}ms");
+ return result;
+ }
+
+
public List ElencoOperatori(int matrOpr, string authkey)
{
Stopwatch stopWatch = new Stopwatch();
@@ -247,6 +295,16 @@ namespace MP.INVE.Data
bool answ = await ExecFlushRedisPattern(pattern);
return answ;
}
+#if false
+
+ public async Task FlushRedisCache(string keyPattern)
+ {
+ await Task.Delay(1);
+ RedisValue pattern = new RedisValue($"{keyPattern}*");
+ bool answ = await ExecFlushRedisPattern(pattern);
+ return answ;
+ }
+#endif
///
/// Esegue flush memoria redis dato pattern
@@ -282,9 +340,10 @@ namespace MP.INVE.Data
#region Private Fields
private const string redisBaseAddr = "MP:INVE";
+ private const string redisSessionBaseAddr = ":Session:";
private const string redisElencoOperatori = redisBaseAddr + ":ListOperatori";
- private const string redisSessionCurrList = redisBaseAddr + ":ListSessHist";
- private const string redisSessionHistList = redisBaseAddr + ":ListSessCurr";
+ private const string redisSessionCurrList = redisBaseAddr + redisSessionBaseAddr + ":ListSessHist";
+ private const string redisSessionHistList = redisBaseAddr + redisSessionBaseAddr + ":ListSessCurr";
private const string redisMagList = redisBaseAddr + ":ListMag";
private static IConfiguration _configuration = null!;