diff --git a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs index 18cec1f..e0a1179 100644 --- a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs +++ b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs @@ -27,19 +27,18 @@ namespace WebDoorCreator.Data.Controllers #region Company methods /// - /// Recupera l'elenco Company (ALL) + /// Company list (All) /// /// public List CompanyAll() { - // init dati necessari List dbResult = new List(); // cerco su DB recuperando set di dati.... using (WDCDataContext localDbCtx = new WDCDataContext(_configuration)) { try { - // recupero intero set... + // extracting entire set dbResult = localDbCtx .DbSetCompany .OrderBy(x => x.CompanyName) @@ -147,7 +146,7 @@ namespace WebDoorCreator.Data.Controllers { try { - // recupero intero set... + // extracting entire set dbResult = localDbCtx .DbSetUsersView .OrderBy(x => x.UserId) @@ -172,7 +171,7 @@ namespace WebDoorCreator.Data.Controllers { try { - // recupero intero set... + // extracting entire set dbResult = localDbCtx .DbSetUsers .OrderBy(x => x.Id) @@ -197,7 +196,7 @@ namespace WebDoorCreator.Data.Controllers { try { - // recupero intero set... + // extracting entire set var risultato = localDbCtx .DbSetUsers .Where(x => x.Id == userId) @@ -237,7 +236,7 @@ namespace WebDoorCreator.Data.Controllers { try { - // recupero intero set... + // extracting entire set dbResult = localDbCtx .DbSetRoles .OrderBy(x => x.Name) @@ -322,5 +321,76 @@ namespace WebDoorCreator.Data.Controllers } #endregion Order methods + + #region Door methods + + /// + /// Getting door data by orderId + /// + /// + public List DoorsGetByOrderId(int orderId) + { + List dbResult = new List(); + // retrieving data from db + using (WDCDataContext localDbCtx = new WDCDataContext(_configuration)) + { + try + { + + // extracting entire set + dbResult = localDbCtx + .DbSetDoor + .Where(x=>x.OrderId == orderId) + .OrderBy(x => x.DoorId) + .ToList(); + } + catch (Exception exc) + { + Log.Error($"Error in DoorsGetAll:{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + + /// + /// Modifying or adding a new door + /// + /// Record to edit or add + /// + public async Task DoorsAddMod(DoorModel addEditRec) + { + bool fatto = false; + //List dbResult = new List(); + using (WDCDataContext localDbCtx = new WDCDataContext(_configuration)) + { + try + { + var currRec = localDbCtx + .DbSetDoor + .Where(x => x.DoorId == addEditRec.DoorId) + .FirstOrDefault(); + if (currRec != null) //if is not null edit the record found + { + currRec.Quantity = addEditRec.Quantity; + localDbCtx.Entry(currRec).State = EntityState.Modified; + } + else //if is null add the record as new in the table + { + localDbCtx + .DbSetDoor + .Add(addEditRec); + } + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante DoorsAddMod: {Environment.NewLine}{exc}"); + } + } + return fatto; + } + + #endregion Door methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Components/OrderList.razor b/WebDoorCreator.UI/Components/OrderList.razor index ca662d5..bf66b33 100644 --- a/WebDoorCreator.UI/Components/OrderList.razor +++ b/WebDoorCreator.UI/Components/OrderList.razor @@ -21,7 +21,7 @@ else @foreach (var item in ListOrdersStatus) { - + @item.DateIns @item.OrderId @item.OrderDescript diff --git a/WebDoorCreator.UI/Components/OrderList.razor.cs b/WebDoorCreator.UI/Components/OrderList.razor.cs index def0b50..8fc09c5 100644 --- a/WebDoorCreator.UI/Components/OrderList.razor.cs +++ b/WebDoorCreator.UI/Components/OrderList.razor.cs @@ -29,7 +29,7 @@ namespace WebDoorCreator.UI.Components protected IJSRuntime JSRuntime { get; set; } = null!; [Parameter] - public EventCallback E_currOrderStatus { get; set; } + public EventCallback E_currOrderStatus { get; set; } #endregion Protected Properties @@ -66,9 +66,10 @@ namespace WebDoorCreator.UI.Components await Task.Delay(1); await InvokeAsync(StateHasChanged); } - private async Task setCurrOrder(string userId) + private async Task setCurrOrder(int userId) { await Task.Delay(1); + await E_currOrderStatus.InvokeAsync(userId); } protected string setPgColor(int progress) diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index 4550a74..77a429b 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -391,7 +391,9 @@ namespace WebDoorCreator.UI.Data #endregion Order status Methods - #region Order methods + /*----------------------------------------------------------------------------------------------------------------------*/ + + #region Order Methods /// /// Add new order @@ -408,7 +410,70 @@ namespace WebDoorCreator.UI.Data return dbResult; } - #endregion Order methods + #endregion Order Methods + + /*----------------------------------------------------------------------------------------------------------------------*/ + + #region Door Methods + /// + /// Doors list by orderId + /// + public async Task?> DoorsGetByOrderId(int orderId) + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = rKeyDoor; + 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.DoorsGetByOrderId(orderId); + 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($"DoorsGetByOrderId | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Update or add door + /// + /// + /// + public async Task DoorsAddMod(DoorModel currRec) + { + var dbResult = await dbController.DoorsAddMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyDoor}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + + #endregion Door Methods + #endregion Public Methods @@ -453,6 +518,7 @@ namespace WebDoorCreator.UI.Data protected const string rKeyUsers = $"{redisBaseAddr}:Cache:Users"; protected const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView"; protected const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles"; + protected const string rKeyDoor = $"{redisBaseAddr}:Cache:Doors"; protected Random rnd = new Random(); @@ -491,1324 +557,5 @@ namespace WebDoorCreator.UI.Data #endregion Private Fields -#if false - - /// - /// 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 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 - - //#endregion Private Methods } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Pages/OrdersHomePage.razor b/WebDoorCreator.UI/Pages/OrdersHomePage.razor index cfcef2a..2e5c12c 100644 --- a/WebDoorCreator.UI/Pages/OrdersHomePage.razor +++ b/WebDoorCreator.UI/Pages/OrdersHomePage.razor @@ -17,7 +17,7 @@ - + @@ -49,6 +49,44 @@ + + diff --git a/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs b/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs index dbca2ee..db196af 100644 --- a/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs +++ b/WebDoorCreator.UI/Pages/OrdersHomePage.razor.cs @@ -61,10 +61,12 @@ namespace WebDoorCreator.UI.Pages protected List? UsersList { get; set; } = null; protected List? RolesList { get; set; } = null; + protected List? DoorsList { get; set; } = null; protected AspNetUsers? currUser { get; set; } = null; protected bool isModRole { get; set; } = false; + protected int currDoorType { get; set; } = 0; protected async Task addNewOrder(string userName) { @@ -84,12 +86,50 @@ namespace WebDoorCreator.UI.Pages var done = await WDService.OrderAdd(addRec); - if(done) + if (done) { NavManager.NavigateTo(NavManager.Uri, true); } } + protected async Task SetCurrDoorType(int doorType) + { + await Task.Delay(1); + currDoorType = doorType; + } + + + protected async Task addOrModDoor(string userName) + { + var user = await _userManager.FindByNameAsync(userName); + + DoorModel? addRec = new DoorModel(); + + if (currDoorType != 0) + { + if (DoorsList != null) + { + addRec = DoorsList.Where(x => x.TypeId == currDoorType).FirstOrDefault(); + } + } + + if (addRec != null) + { + + var done = await WDService.DoorsAddMod(addRec); + + if (done) + { + NavManager.NavigateTo(NavManager.Uri, true); + } + } + } + + protected async Task catchCurrOrder(int orderId) + { + await Task.Delay(1); + DoorsList = await WDService.DoorsGetByOrderId(orderId); + } #endregion Private Methods }