Aggiunta metodi per la gestione del magazzino
This commit is contained in:
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Inventari CORRENTI (=aperti, senza data fine)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<InventorySessionModel> InventSessCurrList()
|
||||
{
|
||||
List<InventorySessionModel> dbResult = new List<InventorySessionModel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Inventari tipo Azienda (TUTTI, chiusi e paerti) filtrati x data
|
||||
/// </summary>
|
||||
/// <param name="FromDate"></param>
|
||||
/// <param name="ToDate"></param>
|
||||
/// <returns></returns>
|
||||
public List<InventorySessionModel> InventSessHistList(DateTime FromDate, DateTime ToDate)
|
||||
{
|
||||
List<InventorySessionModel> dbResult = new List<InventorySessionModel>();
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Elenco Magazzini
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AnagMagModel> ElencoMagazzini()
|
||||
{
|
||||
List<AnagMagModel> dbResult = new List<AnagMagModel>();
|
||||
using (var dbCtx = new MoonPro_InveContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbAnagMag
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MagID)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco operatori
|
||||
@@ -140,11 +80,31 @@ namespace MP.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
#region gestione magazzini
|
||||
|
||||
/// <summary>
|
||||
/// insert di un record sessione
|
||||
/// Elenco Magazzini
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> InsertNewSessione(InventorySessionModel newRec)
|
||||
public List<AnagMagModel> ElencoMagazzini()
|
||||
{
|
||||
List<AnagMagModel> dbResult = new List<AnagMagModel>();
|
||||
using (var dbCtx = new MoonPro_InveContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbAnagMag
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.MagID)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// insert di un record magazzino
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete magazzino
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> 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
|
||||
|
||||
/// <summary>
|
||||
/// delete sessione
|
||||
/// </summary>
|
||||
@@ -188,6 +178,76 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// insert di un record sessione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Inventari tipo Azienda (TUTTI, chiusi e paerti) filtrati x data
|
||||
/// </summary>
|
||||
/// <param name="FromDate"></param>
|
||||
/// <param name="ToDate"></param>
|
||||
/// <returns></returns>
|
||||
public List<InventorySessionModel> InventSessHistList(DateTime FromDate, DateTime ToDate)
|
||||
{
|
||||
List<InventorySessionModel> dbResult = new List<InventorySessionModel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Inventari CORRENTI (=aperti, senza data fine)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<InventorySessionModel> InventSessCurrList()
|
||||
{
|
||||
List<InventorySessionModel> dbResult = new List<InventorySessionModel>();
|
||||
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
|
||||
|
||||
@@ -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<bool> 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<bool> 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<bool> 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<bool> 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<AnagOperatoriModel> 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<bool> FlushRedisCache(string keyPattern)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{keyPattern}*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 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!;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user