Filtro elenco gruppi dato utente (LIMITE selezione)

This commit is contained in:
Samuele Locatelli
2022-01-28 07:56:14 +01:00
parent 3fd818cbbc
commit d7e95de3ce
7 changed files with 113 additions and 11 deletions
+27 -4
View File
@@ -97,10 +97,10 @@ namespace GPW.CORE.Data.Controllers
try
{
// recupero intero set...
var dbResult = localDbCtx
.DbSetAnagFasi
.Where(x => x.IdxFase==idxFase)
.FirstOrDefault();
var dbResult = localDbCtx
.DbSetAnagFasi
.Where(x => x.IdxFase == idxFase)
.FirstOrDefault();
if (dbResult != null)
{
dbResult.Attivo = isActive;
@@ -139,6 +139,29 @@ namespace GPW.CORE.Data.Controllers
return dbResult;
}
public List<AnagGruppiModel> AnagGruppiUser(int idxDipendente)
{
// init dati necessari
List<AnagGruppiModel> dbResult = new List<AnagGruppiModel>();
// cerco su DB recuperando set di dati....
using (GPWContext localDbCtx = new GPWContext(_configuration))
{
try
{
// recupero intero set...
dbResult = localDbCtx
.DbSetAnagGruppi
.Where(x => x.Dipendenti2GruppiNav.Contains(new Dipendenti2GruppiModel() { IdxDipendente = idxDipendente, Gruppo = x.Gruppo }))
.ToList();
}
catch (Exception exc)
{
Log.Error($"Errore in AnagGruppiUser:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
public List<AnagProgettiModel> AnagProjAll(bool onlyActive)
{
// init dati necessari
+5 -5
View File
@@ -10,10 +10,10 @@ namespace GPW.CORE.Data.DbModels
[Table("AnagGruppi")]
public partial class AnagGruppiModel
{
//public AnagGruppiModel()
//{
// DipendentiNav = new HashSet<DipendentiModel>();
//}
public AnagGruppiModel()
{
Dipendenti2GruppiNav = new HashSet<Dipendenti2GruppiModel>();
}
public string Gruppo { get; set; } = null!;
public string? DescrGruppo { get; set; }
public string? CodExt { get; set; }
@@ -22,6 +22,6 @@ namespace GPW.CORE.Data.DbModels
/// </summary>
public bool? ExportEnab { get; set; }
//public virtual ICollection<DipendentiModel> DipendentiNav { get; set; }
public virtual ICollection<Dipendenti2GruppiModel> Dipendenti2GruppiNav { get; set; }
}
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace GPW.CORE.Data.DbModels
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
[Table(" Dipendenti2Gruppi")]
public partial class Dipendenti2GruppiModel
{
public int IdxDipendente { get; set; }
public string Gruppo { get; set; } = null!;
/// <summary>
/// Navigation property to Dipendente
/// </summary>
[ForeignKey("Gruppo")]
public virtual AnagGruppiModel GruppiNav { get; set; } = null!;
/// <summary>
/// Navigation property to Dipendente
/// </summary>
[ForeignKey("IdxDipendente")]
public virtual DipendentiModel DipNav { get; set; } = null!;
}
}
+13
View File
@@ -53,6 +53,7 @@ namespace GPW.CORE.Data
public virtual DbSet<CalcOreFasiModel> DbSetCalcOreFasi { get; set; } = null!;
public virtual DbSet<AnagKeyValueModel> DbSetAnagKeyValue { get; set; } = null!;
public virtual DbSet<AnagTipoTimbModel> DbSetAnagTipoTimb { get; set; } = null!;
public virtual DbSet<Dipendenti2GruppiModel> DbSetDipendenti2Gruppi { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@@ -735,6 +736,18 @@ namespace GPW.CORE.Data
.HasDefaultValueSql("('')");
});
modelBuilder.Entity<Dipendenti2GruppiModel>(entity =>
{
entity.HasKey(e => new { e.IdxDipendente, e.Gruppo });
entity.ToTable("Dipendenti2Gruppi");
entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente");
entity.Property(e => e.Gruppo)
.HasMaxLength(50)
.HasColumnName("gruppo");
});
OnModelCreatingPartial(modelBuilder);
}
@@ -98,7 +98,7 @@ namespace GPW.CORE.WRKLOG.Components
protected async Task ReloadData()
{
gruppiList = await GDataServ.AnagGruppiAll();
gruppiList = await GDataServ.AnagGruppiUser(AppMServ.IdxDipendente);
var allProj = await GDataServ.AnagProjAll();
projList = allProj.Where(x => x.Attivo == true && x.Gruppo == gruppoSel).OrderBy(x => x.ClienteNav.RagSociale).ThenBy(x => x.NomeProj).ToList();
var allFasi = await GDataServ.AnagFasiAll();
@@ -193,7 +193,7 @@ namespace GPW.CORE.WRKLOG.Components
protected async Task ReloadData()
{
gruppiList = await GDataServ.AnagGruppiAll();
gruppiList = await GDataServ.AnagGruppiUser(AppMServ.IdxDipendente);
var allProj = await GDataServ.AnagProjAll();
projList = allProj
.Where(x => x.Attivo == true && x.Gruppo == gruppoSel)
+39
View File
@@ -48,6 +48,7 @@ namespace GPW.CORE.WRKLOG.Data
protected const string rKeyDipendenti = "Cache:Dipendenti";
protected const string rKeyFasiAll = "Cache:FasiAll";
protected const string rKeyGrpAll = "Cache:GrpAll";
protected const string rKeyGrpUser = "Cache:GrpUser";
protected const string rKeyParetoRegAtt = "Cache:ParetoRegAtt";
protected const string rKeyProjAll = "Cache:ProjAll";
protected const string rKeyRilTemp = "Cache:RilTemp";
@@ -264,6 +265,7 @@ namespace GPW.CORE.WRKLOG.Data
return await Task.FromResult(dbResult);
}
#if false
/// <summary>
/// Recupera l'elenco gruppi (tutti)
/// </summary>
@@ -297,6 +299,43 @@ namespace GPW.CORE.WRKLOG.Data
dbResult = new List<AnagGruppiModel>();
}
return await Task.FromResult(dbResult);
}
#endif
/// <summary>
/// Recupera l'elenco gruppi abilitati x il dipendente
/// </summary>
/// <param name="idxDipendente"></param>
/// <returns></returns>
public async Task<List<AnagGruppiModel>> AnagGruppiUser(int idxDipendente)
{
List<AnagGruppiModel>? dbResult = new List<AnagGruppiModel>();
string currKey = $"{rKeyGrpUser}:{idxDipendente}";
string rawData;
var redisDataList = await distributedCache.GetAsync(currKey);
if (redisDataList != null)
{
rawData = Encoding.UTF8.GetString(redisDataList);
dbResult = JsonConvert.DeserializeObject<List<AnagGruppiModel>>(rawData);
}
else
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = dbController.AnagGruppiUser(idxDipendente);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
redisDataList = Encoding.UTF8.GetBytes(rawData);
await distributedCache.SetAsync(currKey, redisDataList, cacheOpt(true));
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB + caching per AnagGruppiUser: {ts.TotalMilliseconds} ms");
}
if (dbResult == null)
{
dbResult = new List<AnagGruppiModel>();
}
return await Task.FromResult(dbResult);
}
/// <summary>