From aee4dddf459f84b08d853b417aa049079d09d449 Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Tue, 7 Mar 2023 14:44:59 +0100 Subject: [PATCH] aggiunta gestione compagnie --- .../Controllers/WebDoorCreatorController.cs | 53 +- .../Components/CompanyList.razor | 8 +- .../Components/CompanyList.razor.cs | 8 + .../Data/WebDoorCreatorService.cs | 2775 +++++++++-------- WebDoorCreator.UI/Pages/CompanyMan.razor | 81 +- WebDoorCreator.UI/Pages/CompanyMan.razor.cs | 131 + 6 files changed, 1668 insertions(+), 1388 deletions(-) diff --git a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs index b1dca2b..2ca3eab 100644 --- a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs +++ b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using NLog; using System; using System.Collections.Generic; @@ -22,6 +23,8 @@ namespace WebDoorCreator.Data.Controllers // Clear database context //Log.Info("Dispose di GWMSController"); } + + #region Company methods /// /// Recupera l'elenco Company (ALL) /// @@ -50,5 +53,53 @@ namespace WebDoorCreator.Data.Controllers } + /// + /// Adding a new company + /// + /// Record to edit or add + /// + public async Task CompanyAddMod(CompanyModel addEditRec) + { + bool fatto = false; + //List dbResult = new List(); + using (WDCDataContext localDbCtx = new WDCDataContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetCompany + .Where(x => x.CompanyId == addEditRec.CompanyId) + .FirstOrDefault(); + if (currRec != null) //if is not null edit the record found + { + currRec.CompanyName = addEditRec.CompanyName; + currRec.CompanyExtCode = addEditRec.CompanyExtCode; + currRec.Address = addEditRec.Address; + currRec.City = addEditRec.City; + currRec.State = addEditRec.State; + currRec.ZipCode = addEditRec.ZipCode; + currRec.VAT = addEditRec.VAT; + currRec.PrivateNote = addEditRec.PrivateNote; + currRec.CompanyToken = addEditRec.CompanyToken; + localDbCtx.Entry(currRec).State = EntityState.Modified; + } + else //if is null add the record as new in the table + { + localDbCtx + .DbSetCompany + .Add(addEditRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante CompanyAddMod;{Environment.NewLine}{exc}"); + } + } + return fatto; + } + #endregion company methods + } } diff --git a/WebDoorCreator.UI/Components/CompanyList.razor b/WebDoorCreator.UI/Components/CompanyList.razor index a7f045b..0631414 100644 --- a/WebDoorCreator.UI/Components/CompanyList.razor +++ b/WebDoorCreator.UI/Components/CompanyList.razor @@ -12,7 +12,7 @@ else Company VAT - Addess + Address Guid @@ -21,10 +21,8 @@ else { - @*@if (!item.Conf) - { - - }*@ + + @item.CompanyName diff --git a/WebDoorCreator.UI/Components/CompanyList.razor.cs b/WebDoorCreator.UI/Components/CompanyList.razor.cs index ac26ae9..1f1a9c9 100644 --- a/WebDoorCreator.UI/Components/CompanyList.razor.cs +++ b/WebDoorCreator.UI/Components/CompanyList.razor.cs @@ -11,6 +11,9 @@ namespace WebDoorCreator.UI.Components [Inject] protected WebDoorCreatorService WDService { get; set; } = null!; + [Parameter] + public EventCallback E_currCompany { get; set; } + #endregion Protected Properties #region Protected Methods @@ -39,6 +42,11 @@ namespace WebDoorCreator.UI.Components await InvokeAsync(StateHasChanged); } + private async Task editRec(CompanyModel currComp) + { + await E_currCompany.InvokeAsync(currComp); + } + #endregion Private Methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index 970e1b6..c3c5ca0 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -5,6 +5,7 @@ using StackExchange.Redis; using System.Diagnostics; using WebDoorCreator.Data.Controllers; using WebDoorCreator.Data.DbModels; +using EgwCoreLib.Razor.Data; namespace WebDoorCreator.UI.Data { @@ -57,6 +58,8 @@ namespace WebDoorCreator.UI.Data #region Public Methods + #region Company methods + /// /// Elenco AKV /// @@ -99,10 +102,108 @@ namespace WebDoorCreator.UI.Data return dbResult; } + /// + /// Aggiornamento record selezionato flusso + /// + /// + /// + public async Task CompanyAddMod(CompanyModel currRec) + { + var dbResult = await dbController.CompanyAddMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyCompany}:cache:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + #endregion Company methods + + /*----------------------------------------------------------------------------------------------------------------------*/ + + #region Cache methods + + /// + /// Esegue flush memoria redis dato pattern + /// + /// + /// + private async Task ExecFlushRedisPattern(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConn.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConn.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + await redisDb.KeyDeleteAsync(item); + } + answ = true; + } + } + + return answ; + } + public async Task FlushRedisCache() + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{redisBaseAddr}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + #endregion Cache methods + + /*----------------------------------------------------------------------------------------------------------------------*/ + + #region Security Methods + public string DecriptData(string encData) + { + return SteamCrypto.DecryptString(encData, passPhrase); + } + public string EncriptData(string rawData) + { + return SteamCrypto.EncryptString(rawData, passPhrase); + } + #endregion Security Methods + /*----------------------------------------------------------------------------------------------------------------------*/ + + #endregion Public Methods #region Protected Fields + #region Private Properties + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan FastCache + { + get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan LongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan UltraLongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); + } + + #endregion Private Properties + protected const string passPhrase = "9eb4660f-8753-46bc-b23b-08759ba03fe9"; //#region Protected Fields @@ -148,1404 +249,1324 @@ namespace WebDoorCreator.UI.Data #endregion Private Fields - //#endregion Public Constructors - - //#region Public Properties - //#endregion Public Properties - - //#region Public Methods - - ///// - ///// Recupera l'elenco fasi (tutte) - ///// - ///// - //public async Task> AnagClientiAll() - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyCliAll}"; - - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagClientiAll(); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagClientiAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Recupera l'elenco fasi (tutte) - ///// - ///// - //public async Task> AnagFasiAll() - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyFasiAll}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagFasiAll(false); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagFasiAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Recupera info x una specifica FASE - ///// - ///// - //public async Task AnagFasiByKey(int idxFase) - //{ - // string source = "DB"; - // AnagFasiModel? dbResult = new AnagFasiModel(); - // // cerco "secca "in redis... - // string currKey = $"{rKeyFasiSearch}:{idxFase}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject(rawData); - // if (tempResult == null) - // { - // dbResult = new AnagFasiModel(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagFasiByKey(idxFase); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagFasiSearch | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Elenco fasi dato progetto - ///// - ///// - ///// - //public async Task?> AnagFasiByProj(int idxProj) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // // cerco "secca "in redis... - // string currKey = $"{rKeyFasiByProj}:{idxProj}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagFasiByProj(idxProj); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagFasiByProj | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Elenco Giustificativi - ///// - ///// - //public async Task?> AnagGiust() - //{ - // string source = "DB"; - // List? dbResult = new List(); - // // cerco "secca "in redis... - // string currKey = $"{rKeyGiust}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagGiust(); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagGiust | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Recupera l'elenco gruppi abilitati x il dipendente - ///// - ///// - ///// - //public async Task> AnagGruppiUser(int idxDipendente) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyGrpUser}:{idxDipendente}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagGruppiUser(idxDipendente); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagGruppiUser | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Dati orario del dipendente indicato - ///// - ///// - ///// - //public async Task AnagOrarioByDip(int idxDip) - //{ - // string source = "DB"; - // AnagOrariModel? dbResult = new AnagOrariModel(); - // string currKey = $"{rKeyAnOrDip}:{idxDip}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject(rawData); - // if (tempResult == null) - // { - // dbResult = new AnagOrariModel(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagOrarioByDip(idxDip); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new AnagOrariModel(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagOrarioByDip | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Recupera l'elenco progetti (tutti) - ///// - ///// - //public async Task> AnagProjAll() - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyProjAll}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.AnagProjAll(false); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"AnagProjAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Lista chiusure aziendali dato periodo - ///// - ///// - ///// - ///// - //public async Task> CalFestFeriePeriodo(DateTime dtStart, DateTime dtEnd) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyCalendari}:ClaFestFer:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.CalFestFeriePeriodo(dtStart, dtEnd); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"CalFestFeriePeriodo | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Recupera l'elenco dei controlli VC19 nel periodo indicato x dipendente - ///// - ///// Dipendente interessato - ///// Data di riferimento (ultima/corrente) - ///// NUm settimane precedenti da recuperare - ///// - //public async Task> CheckVC19List(int idxDipendente, DateTime dtInizio, DateTime dtFine) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyVC19}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.CheckVC19List(idxDipendente, dtInizio, dtFine); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, FastCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"CheckVC19List | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Lista configurazione - ///// - ///// - ///// - ///// - //public async Task> ConfigGetAll() - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyConfig}:Table"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.ConfigGetAll(); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"ConfigGetAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Recupera una singola chaive di config da cache/DB - ///// - ///// - ///// - //public async Task ConfigGetKey(string chiave) - //{ - // string source = "DB"; - // // cerco in cache direttamente la chiave... altrimenti da redis/db - // ConfigModel? keyResult = null; - // string currKey = $"{rKeyConfig}:Dict:{chiave}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject(rawData); - // if (tempResult == null) - // { - // keyResult = new ConfigModel(); - // } - // else - // { - // keyResult = tempResult; - // } - // keyResult = JsonConvert.DeserializeObject(rawData); - // } - // else - // { - // var listConfig = await ConfigGetAll(); - // keyResult = listConfig.FirstOrDefault(x => x.chiave == chiave); - // rawData = JsonConvert.SerializeObject(keyResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"ConfigGetKey | {chiave} | {source} in: {ts.TotalMilliseconds} ms"); - // return await Task.FromResult(keyResult); - //} - - ///// - ///// Recupera l'elenco dei dettagli giornalieri attività di un dipendente, dato periodo riferimento - ///// - ///// Dipendente interessato - ///// Data di riferimento (ultima/corrente) - ///// NUm settimane precedenti da recuperare - ///// - //public async Task> DailyDetails(int idxDipendente, DateTime dtInizio, DateTime dtFine) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyDailyData}:{idxDipendente}:{dtInizio.ToString("yyyy-MM-dd")}:{dtFine.ToString("yyyy-MM-dd")}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.DailyDetails(idxDipendente, dtInizio, dtFine); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, FastCache); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"DailyDetails | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - //public string DecriptData(string encData) - //{ - // return SteamCrypto.DecryptString(encData, passPhrase); - //} - - //public async Task DeviceBySecret(string devSecret) - //{ - // string source = "DB"; - // AnagDeviceModel? dbResult = new AnagDeviceModel(); - // List? cachedResult = new List(); - // string currKey = $"{rKeyUserSecrets}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // cachedResult = new List(); - // } - // else - // { - // cachedResult = tempResult; - // } - // } - - // // controllo se c'è in cache... - // dbResult = cachedResult.FirstOrDefault(x => x.DeviceSecret == devSecret); - // if (dbResult == null) - // { - // source = "REDIS + DB"; - // //altrimenti cerco nel DB ed aggiungo - // dbResult = dbController.AnagDeviceByKey(devSecret); - // if (dbResult != null) - // { - // cachedResult.Add(dbResult); - // rawData = JsonConvert.SerializeObject(cachedResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, LongCache); - // } - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"DeviceBySecret | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Crea un record device - ///// - ///// - ///// - //public async Task DeviceInsert(AnagDeviceModel newRecord) - //{ - // string source = "DB"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // bool fatto = dbController.AnagDeviceInsert(newRecord); - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"DeviceInsert | {source} in: {ts.TotalMilliseconds} ms"); - // await Task.Delay(1); - // return fatto; - //} - - //public async Task> Dip2RuoliGetAll() - //{ - // string source = "DB"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // List? dbResult = new List(); - // string? rawData = await redisDb.StringGetAsync(rKeyDip2Ruoli); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.Dipendenti2RuoliGetAll(); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(rKeyDip2Ruoli, rawData, UltraLongCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"Dip2RuoliGetAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - //public async Task> DipendentiGetAll() - //{ - // string source = "DB"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // List? dbResult = new List(); - // string? rawData = await redisDb.StringGetAsync(rKeyDipendenti); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.DipendentiGetAll(); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(rKeyDipendenti, rawData, FastCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"DipendentiGetAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Update record dipendenti - ///// - ///// - ///// - //public async Task DipendentiUpdate(DipendentiModel currItem) - //{ - // bool answ = false; - // try - // { - // answ = dbController.DipendentiUpdate(currItem); - // // invalido la cache... - // await FlushRedisCache(); - // } - // catch - // { } - // return answ; - //} - - //public void Dispose() - //{ - // // Clear database controller - // dbController.Dispose(); - //} - - //public string EncriptData(string rawData) - //{ - // return SteamCrypto.EncryptString(rawData, passPhrase); - //} - - //public async Task FlushRedisCache() - //{ - // await Task.Delay(1); - // RedisValue pattern = new RedisValue($"{redisBaseAddr}:*"); - // bool answ = await ExecFlushRedisPattern(pattern); - // return answ; - //} - - //public async Task RegAttDelete(RegAttivitaModel currItem) - //{ - // bool answ = false; - // try - // { - // dbController.RegAttDelete(currItem); - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDailyData}:*"); - // await ExecFlushRedisPattern($"{rKeyParetoRegAtt}:*"); - // answ = true; - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Recupera ultima attività dipendente - ///// - ///// - ///// cerca ultima solo tra attive (=true) o tutte (=false) - ///// - //public async Task RegAttLastByDip(int IdxDipendente, bool onlyActive) - //{ - // await Task.Delay(1); - // RegAttivitaModel dbResult = dbController.RegAttLastByDip(IdxDipendente, onlyActive); - // return dbResult; - //} - - //public async Task RegAttUpdate(RegAttivitaModel currItem) - //{ - // bool answ = false; - // try - // { - // dbController.RegAttUpdate(currItem); - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDailyData}:*"); - // await ExecFlushRedisPattern($"{rKeyParetoRegAtt}:*"); - // answ = true; - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Effettua eliminazione record registro malattie (SE non confermato) - ///// - ///// - ///// - //public async Task RegMalattieDelete(RegMalattieModel currItem) - //{ - // bool answ = false; - // try - // { - // answ = dbController.RegMalattieDelete(currItem); - // if (answ) - // { - // // gestisco email notifica... - // string emailDest = _configuration["MailDest:InfoMal"]; - // string urlRedir = _configuration["AdmApp:LinkMal"]; - // StringBuilder sbMain = new StringBuilder(); - // DateTime adesso = DateTime.Now; - // sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato rimosso un record di registrazione malattia"); - // sbMain.AppendLine(""); - // sbMain.Append("
"); - // sbMain.Append($"{currItem.DipNav.Cognome} {currItem.DipNav.Nome} ({currItem.DipNav.Matricola})"); - // //sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - // sbMain.Append("
"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Data Inizio: {currItem.DtInizio}"); - // sbMain.AppendLine($"Numero Giorni: {currItem.NumGG}"); - // sbMain.AppendLine($"Certificato: {currItem.CodCert}"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - // string msgBody = sbMain.ToString(); - // await sendEmail(emailDest, "Eliminazione record Malattia Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); - // } - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDipendenti}:ALL:RegMal:*"); - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Restituisce elenco malattie globali - ///// - ///// max record da recuperare - ///// - //public async Task> RegMalattieGetAll(int maxRecord) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyDipendenti}:ALL:RegMal:{maxRecord}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.RegMalattieGetAll(maxRecord); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, FastCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"RegMalattieGetAll | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Restituisce elenco malattie dipendente - ///// - ///// Dipendente interessato - ///// max record da recuperare - ///// - //public async Task> RegMalattieGetByDip(int idxDipendente, int maxRecord) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyDipendenti}:{idxDipendente}:RegMal:{maxRecord}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.RegMalattieGetByDip(idxDipendente, maxRecord); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, FastCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"RegMalattieGetByDip | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Registra o aggiorna record registro malattie - ///// - ///// - ///// - //public async Task RegMalattieUpsert(RegMalattieModel currItem) - //{ - // bool answ = false; - // try - // { - // // scrivo su DB - // answ = dbController.RegMalattieUpsert(currItem); - // if (answ) - // { - // // recupero info dipendente - // var listDip = await DipendentiGetAll(); - // var currDip = listDip.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente); - // // gestisco email notifica... - // string emailDest = _configuration["MailDest:InfoMal"]; - // string urlRedir = _configuration["AdmApp:LinkMal"]; - // StringBuilder sbMain = new StringBuilder(); - // DateTime adesso = DateTime.Now; - // sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato inserito un nuovo record di registrazione malattia"); - // sbMain.AppendLine(""); - // sbMain.Append("
"); - // sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - // sbMain.Append("
"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Data Inizio: {currItem.DtInizio}"); - // sbMain.AppendLine($"Numero Giorni: {currItem.NumGG}"); - // sbMain.AppendLine($"Certificato: {currItem.CodCert}"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - - // string msgBody = sbMain.ToString(); - // await sendEmail(emailDest, "Nuovo record Malattia Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); - // } - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDipendenti}:ALL:RegMal:*"); - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Effettua eliminazione record registro richieste dipendente (SE non confermato) - ///// - ///// - ///// - //public async Task RegRichiesteDelete(RegRichiesteModel currItem) - //{ - // bool answ = false; - // try - // { - // answ = dbController.RegRichiesteDelete(currItem); - // if (answ) - // { - // // gestisco email notifica... - // string emailDest = _configuration["MailDest:InfoRich"]; - // string urlRedir = _configuration["AdmApp:LinkRich"]; - // StringBuilder sbMain = new StringBuilder(); - // DateTime adesso = DateTime.Now; - // sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato rimosso un record di registrazione richiesta utente"); - // sbMain.AppendLine(""); - // sbMain.Append("
"); - // sbMain.Append($"{currItem.DipNav.Cognome} {currItem.DipNav.Nome} ({currItem.DipNav.Matricola})"); - // //sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - // sbMain.Append("
"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Richiesta: {currItem.CodGiust}"); - // sbMain.AppendLine($"Periodo: {currItem.DtStart} --> {currItem.DtEnd}"); - // sbMain.AppendLine($"Note: {currItem.Note}"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - // string msgBody = sbMain.ToString(); - // await sendEmail(emailDest, $"Eliminazione Richiesta Dipendente | {currItem.CodGiust}", msgBody.Replace($"{Environment.NewLine}", "
")); - // } - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDipendenti}:*"); - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Restituisce elenco richieste dipendente - ///// - ///// Dipendente interessato - ///// Inizio periodo richiesto - ///// Fine periodo richiesto - ///// - //public async Task> RegRichiesteGetByDip(int idxDipendente, DateTime dtFrom, DateTime dtTo) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyDipendenti}:{idxDipendente}:RegRichieste:{dtFrom:yyyyMMdd}:{dtTo:yyyyMMdd}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.RegRichiesteGetByDip(idxDipendente, dtFrom, dtTo); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, FastCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"RegRichiesteGetByDip | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Registra o aggiorna record registro richieste - ///// - ///// - ///// - //public async Task RegRichiesteUpsert(RegRichiesteModel currItem) - //{ - // bool answ = false; - // try - // { - // // scrivo su DB - // answ = dbController.RegRichiesteUpsert(currItem); - // if (answ) - // { - // // recupero info dipendente - // var listDip = await DipendentiGetAll(); - // var currDip = listDip.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente); - // // gestisco email notifica... - // string emailDest = _configuration["MailDest:InfoRich"]; - // string urlRedir = _configuration["AdmApp:LinkRich"]; - // StringBuilder sbMain = new StringBuilder(); - // DateTime adesso = DateTime.Now; - // sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato inserito una nuova richiesta dipendente"); - // sbMain.AppendLine(""); - // sbMain.Append("
"); - // sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - // sbMain.Append("
"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Richiesta: {currItem.CodGiust}"); - // sbMain.AppendLine($"Periodo: {currItem.DtStart} --> {currItem.DtEnd}"); - // sbMain.AppendLine($"Note: {currItem.Note}"); - // sbMain.AppendLine("
"); - // sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - - // string msgBody = sbMain.ToString(); - // await sendEmail(emailDest, $"Nuovo record Richiesta {currItem.CodGiust} Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); - // } - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDipendenti}:*"); - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Recupera l'elenco dei Rilievi temperatura nel periodo indicato x dipendente - ///// - ///// Dipendente interessato - ///// Data di riferimento (ultima/corrente) - ///// NUm settimane precedenti da recuperare - ///// - //public async Task> RilTempList(int idxDipendente, DateTime dtInizio, DateTime dtFine) - //{ - // string source = "DB"; - // List? dbResult = new List(); - // string currKey = $"{rKeyRilTemp}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // string? rawData = await redisDb.StringGetAsync(currKey); - // if (!string.IsNullOrEmpty(rawData)) - // { - // source = "REDIS"; - // var tempResult = JsonConvert.DeserializeObject>(rawData); - // if (tempResult == null) - // { - // dbResult = new List(); - // } - // else - // { - // dbResult = tempResult; - // } - // } - // else - // { - // dbResult = dbController.RilTempList(idxDipendente, dtInizio, dtFine); - // rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - // await redisDb.StringSetAsync(currKey, rawData, FastCache); - // } - // if (dbResult == null) - // { - // dbResult = new List(); - // } - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Debug($"RilTempList | {source} in: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - ///// - ///// Registra update valore temp rilevata - ///// - ///// - ///// - //public async Task RilTempUpdate(RilievoTempModel currItem) - //{ - // bool answ = false; - // try - // { - // dbController.RilTempUpdate(currItem); - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyRilTemp}:*"); - // await ExecFlushRedisPattern($"{rKeyDailyData}:*"); - // answ = true; - // } - // catch - // { } - // return answ; - //} - - //public void rollBackEdit(object item) - //{ - // dbController.rollBackEntity(item); - //} - - ///// - ///// Invio email tramite libreria - ///// - ///// Elenco destinatari separati da virgola - ///// Oggetto email - ///// Corpo Email (HTML) - ///// - //public async Task sendEmailAsync(string destList, string subject, string message) - //{ - // bool fatto = false; - // List emailDestList = destList.Split(",").ToList(); - // foreach (var dest in emailDestList) - // { - // try - // { - // await _emailSender.SendEmailAsync(dest, subject, message); - // fatto = true; - // } - // catch (Exception exc) - // { - // Log.Error($"Eccezione durante invio email:{Environment.NewLine}dest: {dest} | subject {subject}{Environment.NewLine}{exc}"); - // } - // } - // return fatto; - //} - - ///// - ///// Elenco timbrature di un giorno - ///// - ///// - ///// - ///// - //public async Task> TimbratureDay(DateTime dateRif, int IdxDip) - //{ - // await Task.Delay(1); - // List? dbResult = new List(); - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // dbResult = dbController.TimbratureDay(dateRif, IdxDip); - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Trace($"Effettuata lettura da DB per TimbratureDay: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - //public async Task TimbratureDelete(TimbratureModel currItem) - //{ - // bool answ = false; - // try - // { - // dbController.TimbratureDelete(currItem); - // // invalido la cache... - // await FlushRedisCache(); - // answ = true; - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Inserimento richeista mancata timbratura - ///// - ///// - ///// - //public async Task TimbratureInsRichiesta(TimbratureModel currItem) - //{ - // bool answ = false; - // try - // { - // // aggiorna i campi x mancata timbratura (hard coded) - // currItem.CodTipoTimb = "NoTim"; - // currItem.Approv = false; - // // upsert! - // dbController.TimbratureUpdate(currItem); - // Log.Info($"Registrata richiesta Mancata TImbratura | idxDip {currItem.IdxDipendente} | data-ora: {currItem.DataOra} | isEntrata: {currItem.Entrata}"); - // // invalido la cache... - // await FlushRedisCache(); - // answ = true; - // } - // catch - // { } - // return answ; - //} - - ///// - ///// Elenco di tutte le timbrature richieste (= NON approvate) - ///// - ///// - //public async Task> TimbratureRichieste() - //{ - // await Task.Delay(1); - // List? dbResult = new List(); - // Stopwatch stopWatch = new Stopwatch(); - // stopWatch.Start(); - // dbResult = dbController.TimbratureRichieste(); - // stopWatch.Stop(); - // TimeSpan ts = stopWatch.Elapsed; - // Log.Trace($"Effettuata lettura da DB per TimbratureRichieste: {ts.TotalMilliseconds} ms"); - // return dbResult; - //} - - //public async Task TimbratureUpdate(TimbratureModel currItem) - //{ - // bool answ = false; - // try - // { - // dbController.TimbratureUpdate(currItem); - // // invalido la cache... - // await ExecFlushRedisPattern($"{rKeyDailyData}:*"); - // answ = true; - // } - // catch - // { } - // return answ; - //} - //protected const string rKeyAnOrDip = $"{redisBaseAddr}:Cache:AnOrariDip"; - - //protected const string rKeyCalcOreFase = $"{redisBaseAddr}:Cache:CalcOreFase"; - - //protected const string rKeyCalcOreProj = $"{redisBaseAddr}:Cache:CalcOreProj"; - - //protected const string rKeyCalendari = $"{redisBaseAddr}:Cache:Calendari"; - - //protected const string rKeyCliAll = $"{redisBaseAddr}:Cache:CliAll"; - - //protected const string rKeyConfig = $"{redisBaseAddr}:Cache:Config"; - - //protected const string rKeyDailyData = $"{redisBaseAddr}:Cache:DailyData"; - - //protected const string rKeyDip2Ruoli = $"{redisBaseAddr}:Cache:Dip2Ruoli"; - - //protected const string rKeyDipendenti = $"{redisBaseAddr}:Cache:Dipendenti"; - - //protected const string rKeyFasiAll = $"{redisBaseAddr}:Cache:FasiAll"; - - //protected const string rKeyFasiByProj = $"{redisBaseAddr}:Cache:FasiByProj"; - - //protected const string rKeyFasiSearch = $"{redisBaseAddr}:Cache:FasiSearch"; - - //protected const string rKeyGiust = $"{redisBaseAddr}:Cache:Giustif"; - - //protected const string rKeyGrpAll = $"{redisBaseAddr}:Cache:GrpAll"; - - //protected const string rKeyGrpUser = $"{redisBaseAddr}:Cache:GrpUser"; - - //protected const string rKeyParetoRegAtt = $"{redisBaseAddr}:Cache:ParetoRegAtt"; - - //protected const string rKeyProjAll = $"{redisBaseAddr}:Cache:ProjAll"; - - //protected const string rKeyRilTemp = $"{redisBaseAddr}:Cache:RilTemp"; - - //protected const string rKeyUserSecrets = $"{redisBaseAddr}:Cache:DevSecrets"; - - //protected const string rKeyVC19 = $"{redisBaseAddr}:Cache:VC19"; - - //protected const string rKeyVetoIns = $"{redisBaseAddr}:Cache:VetoInsert"; - - //protected const string rKeyWeekStats = $"{redisBaseAddr}:Cache:WeekStats"; - - //protected static string connStringBBM = ""; - //#endregion Protected Fields - - //#region Protected Methods - - ///// - ///// Invio email tramite libreria - ///// - ///// - ///// - ///// - ///// - //protected async Task sendEmail(string destList, string subject, string message) - //{ - // List emailDestList = destList.Split(",").ToList(); - // foreach (var dest in emailDestList) - // { - // try - // { - // await _emailSender.SendEmailAsync(dest, subject, message); - // } - // catch (Exception exc) - // { - // Log.Error($"Eccezione durante invio email:{Environment.NewLine}dest: {dest} | subject {subject}{Environment.NewLine}{exc}"); - // } - // } - //} - - //#endregion Protected Methods - - //#region Private Fields - - //private List cachedDataList = new List(); - - //#endregion Private Fields - - //#region Private Properties - - #region Private Properties +#if false /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// Recupera l'elenco fasi (tutte) /// - private TimeSpan FastCache + /// + public async Task> AnagClientiAll() { - get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyCliAll}"; + + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagClientiAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagClientiAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; } /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// Recupera l'elenco fasi (tutte) /// - private TimeSpan LongCache + /// + public async Task> AnagFasiAll() { - get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyFasiAll}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagFasiAll(false); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagFasiAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; } /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// Recupera info x una specifica FASE /// - private TimeSpan UltraLongCache + /// + public async Task AnagFasiByKey(int idxFase) { - get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); + string source = "DB"; + AnagFasiModel? dbResult = new AnagFasiModel(); + // cerco "secca "in redis... + string currKey = $"{rKeyFasiSearch}:{idxFase}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject(rawData); + if (tempResult == null) + { + dbResult = new AnagFasiModel(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagFasiByKey(idxFase); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagFasiSearch | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; } - #endregion Private Properties + /// + /// Elenco fasi dato progetto + /// + /// + /// + public async Task?> AnagFasiByProj(int idxProj) + { + string source = "DB"; + List? dbResult = new List(); + // cerco "secca "in redis... + string currKey = $"{rKeyFasiByProj}:{idxProj}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagFasiByProj(idxProj); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagFasiByProj | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Elenco Giustificativi + /// + /// + public async Task?> AnagGiust() + { + string source = "DB"; + List? dbResult = new List(); + // cerco "secca "in redis... + string currKey = $"{rKeyGiust}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagGiust(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagGiust | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Recupera l'elenco gruppi abilitati x il dipendente + /// + /// + /// + public async Task> AnagGruppiUser(int idxDipendente) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyGrpUser}:{idxDipendente}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagGruppiUser(idxDipendente); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagGruppiUser | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Dati orario del dipendente indicato + /// + /// + /// + public async Task AnagOrarioByDip(int idxDip) + { + string source = "DB"; + AnagOrariModel? dbResult = new AnagOrariModel(); + string currKey = $"{rKeyAnOrDip}:{idxDip}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject(rawData); + if (tempResult == null) + { + dbResult = new AnagOrariModel(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagOrarioByDip(idxDip); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new AnagOrariModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagOrarioByDip | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Recupera l'elenco progetti (tutti) + /// + /// + public async Task> AnagProjAll() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyProjAll}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.AnagProjAll(false); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"AnagProjAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Lista chiusure aziendali dato periodo + /// + /// + /// + /// + public async Task> CalFestFeriePeriodo(DateTime dtStart, DateTime dtEnd) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyCalendari}:ClaFestFer:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.CalFestFeriePeriodo(dtStart, dtEnd); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"CalFestFeriePeriodo | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Recupera l'elenco dei controlli VC19 nel periodo indicato x dipendente + /// + /// Dipendente interessato + /// Data di riferimento (ultima/corrente) + /// NUm settimane precedenti da recuperare + /// + public async Task> CheckVC19List(int idxDipendente, DateTime dtInizio, DateTime dtFine) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyVC19}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.CheckVC19List(idxDipendente, dtInizio, dtFine); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"CheckVC19List | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Lista configurazione + /// + /// + /// + /// + public async Task> ConfigGetAll() + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyConfig}:Table"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.ConfigGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ConfigGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Recupera una singola chaive di config da cache/DB + /// + /// + /// + public async Task ConfigGetKey(string chiave) + { + string source = "DB"; + // cerco in cache direttamente la chiave... altrimenti da redis/db + ConfigModel? keyResult = null; + string currKey = $"{rKeyConfig}:Dict:{chiave}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject(rawData); + if (tempResult == null) + { + keyResult = new ConfigModel(); + } + else + { + keyResult = tempResult; + } + keyResult = JsonConvert.DeserializeObject(rawData); + } + else + { + var listConfig = await ConfigGetAll(); + keyResult = listConfig.FirstOrDefault(x => x.chiave == chiave); + rawData = JsonConvert.SerializeObject(keyResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ConfigGetKey | {chiave} | {source} in: {ts.TotalMilliseconds} ms"); + return await Task.FromResult(keyResult); + } + + /// + /// Recupera l'elenco dei dettagli giornalieri attività di un dipendente, dato periodo riferimento + /// + /// Dipendente interessato + /// Data di riferimento (ultima/corrente) + /// NUm settimane precedenti da recuperare + /// + public async Task> DailyDetails(int idxDipendente, DateTime dtInizio, DateTime dtFine) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyDailyData}:{idxDipendente}:{dtInizio.ToString("yyyy-MM-dd")}:{dtFine.ToString("yyyy-MM-dd")}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.DailyDetails(idxDipendente, dtInizio, dtFine); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DailyDetails | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + + + public async Task DeviceBySecret(string devSecret) + { + string source = "DB"; + AnagDeviceModel? dbResult = new AnagDeviceModel(); + List? cachedResult = new List(); + string currKey = $"{rKeyUserSecrets}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + cachedResult = new List(); + } + else + { + cachedResult = tempResult; + } + } + + // controllo se c'è in cache... + dbResult = cachedResult.FirstOrDefault(x => x.DeviceSecret == devSecret); + if (dbResult == null) + { + source = "REDIS + DB"; + //altrimenti cerco nel DB ed aggiungo + dbResult = dbController.AnagDeviceByKey(devSecret); + if (dbResult != null) + { + cachedResult.Add(dbResult); + rawData = JsonConvert.SerializeObject(cachedResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DeviceBySecret | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Crea un record device + /// + /// + /// + public async Task DeviceInsert(AnagDeviceModel newRecord) + { + string source = "DB"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + bool fatto = dbController.AnagDeviceInsert(newRecord); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DeviceInsert | {source} in: {ts.TotalMilliseconds} ms"); + await Task.Delay(1); + return fatto; + } + + public async Task> Dip2RuoliGetAll() + { + string source = "DB"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List? dbResult = new List(); + string? rawData = await redisDb.StringGetAsync(rKeyDip2Ruoli); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.Dipendenti2RuoliGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(rKeyDip2Ruoli, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"Dip2RuoliGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + public async Task> DipendentiGetAll() + { + string source = "DB"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List? dbResult = new List(); + string? rawData = await redisDb.StringGetAsync(rKeyDipendenti); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.DipendentiGetAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(rKeyDipendenti, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DipendentiGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Update record dipendenti + /// + /// + /// + public async Task DipendentiUpdate(DipendentiModel currItem) + { + bool answ = false; + try + { + answ = dbController.DipendentiUpdate(currItem); + // invalido la cache... + await FlushRedisCache(); + } + catch + { } + return answ; + } + + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + } + + + + + + public async Task RegAttDelete(RegAttivitaModel currItem) + { + bool answ = false; + try + { + dbController.RegAttDelete(currItem); + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDailyData}:*"); + await ExecFlushRedisPattern($"{rKeyParetoRegAtt}:*"); + answ = true; + } + catch + { } + return answ; + } + + /// + /// Recupera ultima attività dipendente + /// + /// + /// cerca ultima solo tra attive (=true) o tutte (=false) + /// + public async Task RegAttLastByDip(int IdxDipendente, bool onlyActive) + { + await Task.Delay(1); + RegAttivitaModel dbResult = dbController.RegAttLastByDip(IdxDipendente, onlyActive); + return dbResult; + } + + public async Task RegAttUpdate(RegAttivitaModel currItem) + { + bool answ = false; + try + { + dbController.RegAttUpdate(currItem); + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDailyData}:*"); + await ExecFlushRedisPattern($"{rKeyParetoRegAtt}:*"); + answ = true; + } + catch + { } + return answ; + } + + /// + /// Effettua eliminazione record registro malattie (SE non confermato) + /// + /// + /// + public async Task RegMalattieDelete(RegMalattieModel currItem) + { + bool answ = false; + try + { + answ = dbController.RegMalattieDelete(currItem); + if (answ) + { + // gestisco email notifica... + string emailDest = _configuration["MailDest:InfoMal"]; + string urlRedir = _configuration["AdmApp:LinkMal"]; + StringBuilder sbMain = new StringBuilder(); + DateTime adesso = DateTime.Now; + sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato rimosso un record di registrazione malattia"); + sbMain.AppendLine(""); + sbMain.Append("
"); + sbMain.Append($"{currItem.DipNav.Cognome} {currItem.DipNav.Nome} ({currItem.DipNav.Matricola})"); + //sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); + sbMain.Append("
"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Data Inizio: {currItem.DtInizio}"); + sbMain.AppendLine($"Numero Giorni: {currItem.NumGG}"); + sbMain.AppendLine($"Certificato: {currItem.CodCert}"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); + string msgBody = sbMain.ToString(); + await sendEmail(emailDest, "Eliminazione record Malattia Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); + } + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDipendenti}:ALL:RegMal:*"); + } + catch + { } + return answ; + } + + /// + /// Restituisce elenco malattie globali + /// + /// max record da recuperare + /// + public async Task> RegMalattieGetAll(int maxRecord) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyDipendenti}:ALL:RegMal:{maxRecord}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.RegMalattieGetAll(maxRecord); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"RegMalattieGetAll | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Restituisce elenco malattie dipendente + /// + /// Dipendente interessato + /// max record da recuperare + /// + public async Task> RegMalattieGetByDip(int idxDipendente, int maxRecord) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyDipendenti}:{idxDipendente}:RegMal:{maxRecord}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.RegMalattieGetByDip(idxDipendente, maxRecord); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"RegMalattieGetByDip | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Registra o aggiorna record registro malattie + /// + /// + /// + public async Task RegMalattieUpsert(RegMalattieModel currItem) + { + bool answ = false; + try + { + // scrivo su DB + answ = dbController.RegMalattieUpsert(currItem); + if (answ) + { + // recupero info dipendente + var listDip = await DipendentiGetAll(); + var currDip = listDip.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente); + // gestisco email notifica... + string emailDest = _configuration["MailDest:InfoMal"]; + string urlRedir = _configuration["AdmApp:LinkMal"]; + StringBuilder sbMain = new StringBuilder(); + DateTime adesso = DateTime.Now; + sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato inserito un nuovo record di registrazione malattia"); + sbMain.AppendLine(""); + sbMain.Append("
"); + sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); + sbMain.Append("
"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Data Inizio: {currItem.DtInizio}"); + sbMain.AppendLine($"Numero Giorni: {currItem.NumGG}"); + sbMain.AppendLine($"Certificato: {currItem.CodCert}"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); + + string msgBody = sbMain.ToString(); + await sendEmail(emailDest, "Nuovo record Malattia Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); + } + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDipendenti}:ALL:RegMal:*"); + } + catch + { } + return answ; + } + + /// + /// Effettua eliminazione record registro richieste dipendente (SE non confermato) + /// + /// + /// + public async Task RegRichiesteDelete(RegRichiesteModel currItem) + { + bool answ = false; + try + { + answ = dbController.RegRichiesteDelete(currItem); + if (answ) + { + // gestisco email notifica... + string emailDest = _configuration["MailDest:InfoRich"]; + string urlRedir = _configuration["AdmApp:LinkRich"]; + StringBuilder sbMain = new StringBuilder(); + DateTime adesso = DateTime.Now; + sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato rimosso un record di registrazione richiesta utente"); + sbMain.AppendLine(""); + sbMain.Append("
"); + sbMain.Append($"{currItem.DipNav.Cognome} {currItem.DipNav.Nome} ({currItem.DipNav.Matricola})"); + //sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); + sbMain.Append("
"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Richiesta: {currItem.CodGiust}"); + sbMain.AppendLine($"Periodo: {currItem.DtStart} --> {currItem.DtEnd}"); + sbMain.AppendLine($"Note: {currItem.Note}"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); + string msgBody = sbMain.ToString(); + await sendEmail(emailDest, $"Eliminazione Richiesta Dipendente | {currItem.CodGiust}", msgBody.Replace($"{Environment.NewLine}", "
")); + } + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDipendenti}:*"); + } + catch + { } + return answ; + } + + /// + /// Restituisce elenco richieste dipendente + /// + /// Dipendente interessato + /// Inizio periodo richiesto + /// Fine periodo richiesto + /// + public async Task> RegRichiesteGetByDip(int idxDipendente, DateTime dtFrom, DateTime dtTo) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyDipendenti}:{idxDipendente}:RegRichieste:{dtFrom:yyyyMMdd}:{dtTo:yyyyMMdd}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.RegRichiesteGetByDip(idxDipendente, dtFrom, dtTo); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"RegRichiesteGetByDip | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Registra o aggiorna record registro richieste + /// + /// + /// + public async Task RegRichiesteUpsert(RegRichiesteModel currItem) + { + bool answ = false; + try + { + // scrivo su DB + answ = dbController.RegRichiesteUpsert(currItem); + if (answ) + { + // recupero info dipendente + var listDip = await DipendentiGetAll(); + var currDip = listDip.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente); + // gestisco email notifica... + string emailDest = _configuration["MailDest:InfoRich"]; + string urlRedir = _configuration["AdmApp:LinkRich"]; + StringBuilder sbMain = new StringBuilder(); + DateTime adesso = DateTime.Now; + sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato inserito una nuova richiesta dipendente"); + sbMain.AppendLine(""); + sbMain.Append("
"); + sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); + sbMain.Append("
"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Richiesta: {currItem.CodGiust}"); + sbMain.AppendLine($"Periodo: {currItem.DtStart} --> {currItem.DtEnd}"); + sbMain.AppendLine($"Note: {currItem.Note}"); + sbMain.AppendLine("
"); + sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); + + string msgBody = sbMain.ToString(); + await sendEmail(emailDest, $"Nuovo record Richiesta {currItem.CodGiust} Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); + } + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDipendenti}:*"); + } + catch + { } + return answ; + } + + /// + /// Recupera l'elenco dei Rilievi temperatura nel periodo indicato x dipendente + /// + /// Dipendente interessato + /// Data di riferimento (ultima/corrente) + /// NUm settimane precedenti da recuperare + /// + public async Task> RilTempList(int idxDipendente, DateTime dtInizio, DateTime dtFine) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyRilTemp}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.RilTempList(idxDipendente, dtInizio, dtFine); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"RilTempList | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Registra update valore temp rilevata + /// + /// + /// + public async Task RilTempUpdate(RilievoTempModel currItem) + { + bool answ = false; + try + { + dbController.RilTempUpdate(currItem); + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyRilTemp}:*"); + await ExecFlushRedisPattern($"{rKeyDailyData}:*"); + answ = true; + } + catch + { } + return answ; + } + + public void rollBackEdit(object item) + { + dbController.rollBackEntity(item); + } + + /// + /// Invio email tramite libreria + /// + /// Elenco destinatari separati da virgola + /// Oggetto email + /// Corpo Email (HTML) + /// + public async Task sendEmailAsync(string destList, string subject, string message) + { + bool fatto = false; + List emailDestList = destList.Split(",").ToList(); + foreach (var dest in emailDestList) + { + try + { + await _emailSender.SendEmailAsync(dest, subject, message); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante invio email:{Environment.NewLine}dest: {dest} | subject {subject}{Environment.NewLine}{exc}"); + } + } + return fatto; + } + + /// + /// Elenco timbrature di un giorno + /// + /// + /// + /// + public async Task> TimbratureDay(DateTime dateRif, int IdxDip) + { + await Task.Delay(1); + List? dbResult = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.TimbratureDay(dateRif, IdxDip); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB per TimbratureDay: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + public async Task TimbratureDelete(TimbratureModel currItem) + { + bool answ = false; + try + { + dbController.TimbratureDelete(currItem); + // invalido la cache... + await FlushRedisCache(); + answ = true; + } + catch + { } + return answ; + } + + /// + /// Inserimento richeista mancata timbratura + /// + /// + /// + public async Task TimbratureInsRichiesta(TimbratureModel currItem) + { + bool answ = false; + try + { + // aggiorna i campi x mancata timbratura (hard coded) + currItem.CodTipoTimb = "NoTim"; + currItem.Approv = false; + // upsert! + dbController.TimbratureUpdate(currItem); + Log.Info($"Registrata richiesta Mancata TImbratura | idxDip {currItem.IdxDipendente} | data-ora: {currItem.DataOra} | isEntrata: {currItem.Entrata}"); + // invalido la cache... + await FlushRedisCache(); + answ = true; + } + catch + { } + return answ; + } + + /// + /// Elenco di tutte le timbrature richieste (= NON approvate) + /// + /// + public async Task> TimbratureRichieste() + { + await Task.Delay(1); + List? dbResult = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.TimbratureRichieste(); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB per TimbratureRichieste: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + public async Task TimbratureUpdate(TimbratureModel currItem) + { + bool answ = false; + try + { + dbController.TimbratureUpdate(currItem); + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyDailyData}:*"); + answ = true; + } + catch + { } + return answ; + } + protected const string rKeyAnOrDip = $"{redisBaseAddr}:Cache:AnOrariDip"; + + protected const string rKeyCalcOreFase = $"{redisBaseAddr}:Cache:CalcOreFase"; + + protected const string rKeyCalcOreProj = $"{redisBaseAddr}:Cache:CalcOreProj"; + + protected const string rKeyCalendari = $"{redisBaseAddr}:Cache:Calendari"; + + protected const string rKeyCliAll = $"{redisBaseAddr}:Cache:CliAll"; + + protected const string rKeyConfig = $"{redisBaseAddr}:Cache:Config"; + + protected const string rKeyDailyData = $"{redisBaseAddr}:Cache:DailyData"; + + protected const string rKeyDip2Ruoli = $"{redisBaseAddr}:Cache:Dip2Ruoli"; + + protected const string rKeyDipendenti = $"{redisBaseAddr}:Cache:Dipendenti"; + + protected const string rKeyFasiAll = $"{redisBaseAddr}:Cache:FasiAll"; + + protected const string rKeyFasiByProj = $"{redisBaseAddr}:Cache:FasiByProj"; + + protected const string rKeyFasiSearch = $"{redisBaseAddr}:Cache:FasiSearch"; + + protected const string rKeyGiust = $"{redisBaseAddr}:Cache:Giustif"; + + protected const string rKeyGrpAll = $"{redisBaseAddr}:Cache:GrpAll"; + + protected const string rKeyGrpUser = $"{redisBaseAddr}:Cache:GrpUser"; + + protected const string rKeyParetoRegAtt = $"{redisBaseAddr}:Cache:ParetoRegAtt"; + + protected const string rKeyProjAll = $"{redisBaseAddr}:Cache:ProjAll"; + + protected const string rKeyRilTemp = $"{redisBaseAddr}:Cache:RilTemp"; + + protected const string rKeyUserSecrets = $"{redisBaseAddr}:Cache:DevSecrets"; + + protected const string rKeyVC19 = $"{redisBaseAddr}:Cache:VC19"; + + protected const string rKeyVetoIns = $"{redisBaseAddr}:Cache:VetoInsert"; + + protected const string rKeyWeekStats = $"{redisBaseAddr}:Cache:WeekStats"; + + protected static string connStringBBM = ""; + + /// + /// Invio email tramite libreria + /// + /// + /// + /// + /// + protected async Task sendEmail(string destList, string subject, string message) + { + List emailDestList = destList.Split(",").ToList(); + foreach (var dest in emailDestList) + { + try + { + await _emailSender.SendEmailAsync(dest, subject, message); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante invio email:{Environment.NewLine}dest: {dest} | subject {subject}{Environment.NewLine}{exc}"); + } + } + } + + private List cachedDataList = new List(); +#endif + + //#endregion Private Properties //#region Private Methods - ///// - ///// Esegue flush memoria redis dato pattern - ///// - ///// - ///// - //private async Task ExecFlushRedisPattern(RedisValue pattern) - //{ - // bool answ = false; - // var listEndpoints = redisConn.GetEndPoints(); - // foreach (var endPoint in listEndpoints) - // { - // //var server = redisConnAdmin.GetServer(listEndpoints[0]); - // var server = redisConn.GetServer(endPoint); - // if (server != null) - // { - // var keyList = server.Keys(redisDb.Database, pattern); - // foreach (var item in keyList) - // { - // await redisDb.KeyDeleteAsync(item); - // } - // answ = true; - // } - // } - - // return answ; - //} - //#endregion Private Methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Pages/CompanyMan.razor b/WebDoorCreator.UI/Pages/CompanyMan.razor index 671e64b..0e01888 100644 --- a/WebDoorCreator.UI/Pages/CompanyMan.razor +++ b/WebDoorCreator.UI/Pages/CompanyMan.razor @@ -1,9 +1,80 @@ @page "/CompanyMan" +@using WebDoorCreator.UI.Components -
-

Company Management

-
-
General Application company list
- + + +
+
+
+ Company Management +
+
+ + +
+
+
+
General Application company list
+ +
+
+
+
+ + + + \ No newline at end of file diff --git a/WebDoorCreator.UI/Pages/CompanyMan.razor.cs b/WebDoorCreator.UI/Pages/CompanyMan.razor.cs index 2326de3..93d4ac6 100644 --- a/WebDoorCreator.UI/Pages/CompanyMan.razor.cs +++ b/WebDoorCreator.UI/Pages/CompanyMan.razor.cs @@ -13,10 +13,141 @@ using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; using WebDoorCreator.UI; using WebDoorCreator.UI.Shared; +using WebDoorCreator.Data.DbModels; +using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Pages { public partial class CompanyMan { + [Inject] + protected WebDoorCreatorService WDService { get; set; } = null!; + + protected CompanyModel? currCompany { get; set; } = null; + + protected int _companyId = 0; + protected int companyId + { + get => _companyId; + set { _companyId = value; } + } + + protected string _companyExtCode = ""; + protected string companyExtCode + { + get => _companyExtCode; + set { _companyExtCode = value; } + } + + protected string _companyName = ""; + protected string companyName + { + get => _companyName; + set { _companyName = value; } + } + + protected string _address = ""; + protected string address + { + get => _address; + set { _address = value; } + } + + protected int _zipCode = 0; + protected int zipCode + { + get => _zipCode; + set { _zipCode = value; } + } + + protected string _city = ""; + protected string city + { + get => _city; + set { _city = value; } + } + + protected string _state = ""; + protected string state + { + get => _state; + set { _state = value; } + } + protected string _vat = ""; + protected string vat + { + get => _vat; + set { _vat = value; } + } + protected string _privateNote = ""; + protected string privateNote + { + get => _privateNote; + set { _privateNote = value; } + } + protected string _companyToken = ""; + protected string companyToken + { + get => _companyToken; + set { _companyToken = value; } + } + + protected async Task addModNewCompany() + { + Guid newCompToken = Guid.NewGuid(); + bool done = false; + if (currCompany == null) + { + var newComp = new CompanyModel() + { + CompanyExtCode = companyExtCode, + CompanyName = companyName, + Address = address, + ZipCode = zipCode, + City = city, + State = state, + VAT = vat, + PrivateNote = privateNote, + CompanyToken = newCompToken.ToString() + }; + + done = await WDService.CompanyAddMod(newComp); + } + else + { + var editComp = new CompanyModel() + { + CompanyId = companyId, + CompanyExtCode = companyExtCode, + CompanyName = companyName, + Address = address, + ZipCode = zipCode, + City = city, + State = state, + VAT = vat, + PrivateNote = privateNote, + CompanyToken = companyToken + }; + done = await WDService.CompanyAddMod(editComp); + } + } + + protected async Task catchCurrComp(CompanyModel? selComp) + { + await Task.Delay(1); + if(selComp != null) + { + currCompany = selComp; + companyExtCode = currCompany.CompanyExtCode; + companyName = currCompany.CompanyName; + address = currCompany.Address; + zipCode = currCompany.ZipCode; + city = currCompany.City; + state = currCompany.State; + vat = currCompany.VAT; + privateNote = currCompany.PrivateNote; + companyToken = currCompany.CompanyToken; + } + } } } \ No newline at end of file