Aggiunti metodi per inserimento nuova sessione +
delete sessione
This commit is contained in:
@@ -36,6 +36,7 @@ namespace MP.Data.Controllers
|
||||
dbResult = dbCtx
|
||||
.DbInveSess
|
||||
.Where(x => x.DtEnd == null)
|
||||
.Include(m=>m.AnagMagNav)
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.DtStart)
|
||||
.ToList();
|
||||
@@ -57,6 +58,7 @@ namespace MP.Data.Controllers
|
||||
dbResult = dbCtx
|
||||
.DbInveSess
|
||||
.Where(x => x.DtStart >= FromDate && x.DtStart <= ToDate && x.DtEnd != null)
|
||||
.Include(m=>m.AnagMagNav)
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.DtStart)
|
||||
.ToList();
|
||||
@@ -88,6 +90,23 @@ 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
|
||||
@@ -120,6 +139,55 @@ namespace MP.Data.Controllers
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// delete sessione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> deleteSessione(InventorySessionModel record)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (var dbCtx = new MoonPro_InveContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
dbCtx
|
||||
.DbInveSess
|
||||
.Remove(record);
|
||||
await dbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante deleteSessione{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
@@ -66,6 +66,21 @@ namespace MP.INVE.Data
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<bool> InsertNewSessione(InventorySessionModel newSess)
|
||||
{
|
||||
// aggiungo record al DB
|
||||
bool answ = await dbController.InsertNewSessione(newSess);
|
||||
|
||||
return answ;
|
||||
}
|
||||
public async Task<bool> deleteSessione(InventorySessionModel session)
|
||||
{
|
||||
// elimino record dal DB
|
||||
bool answ = await dbController.deleteSessione(session);
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public List<AnagOperatoriModel> ElencoOperatori(int matrOpr, string authkey)
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -143,6 +158,36 @@ namespace MP.INVE.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<AnagMagModel> ElencoMagazzini()
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
List<AnagMagModel> result = new List<AnagMagModel>();
|
||||
string source = "DB";
|
||||
// cerco in redis...
|
||||
RedisValue rawData = redisDb.StringGet(redisMagList);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<AnagMagModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.ElencoMagazzini();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSetAsync(redisMagList, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ElencoMagazzini Read from {source}: {ts.TotalMilliseconds}ms");
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AnagMagModel>();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<InventorySessionModel> InventSessHistList(DateTime dtStart, DateTime dtEnd)
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -195,6 +240,42 @@ namespace MP.INVE.Data
|
||||
double rndValue = (double)stdMinutes + (double)rand.Next(1, 60) / 60;
|
||||
return TimeSpan.FromMinutes(rndValue);
|
||||
}
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddr}*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConnAdmin.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
// brutalmente rimuovo intero contenuto DB... DANGER
|
||||
//await server.FlushDatabaseAsync();
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
@@ -204,6 +285,7 @@ namespace MP.INVE.Data
|
||||
private const string redisElencoOperatori = redisBaseAddr + ":ListOperatori";
|
||||
private const string redisSessionCurrList = redisBaseAddr + ":ListSessHist";
|
||||
private const string redisSessionHistList = redisBaseAddr + ":ListSessCurr";
|
||||
private const string redisMagList = redisBaseAddr + ":ListMag";
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static ILogger<MiDataService> _logger = null!;
|
||||
|
||||
Reference in New Issue
Block a user