diff --git a/.gitignore b/.gitignore index 4ec6b66..9b60144 100644 --- a/.gitignore +++ b/.gitignore @@ -362,3 +362,4 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd /.vs/ApiPolo/v17/.suo +/.vs/ApiPolo/v17/.futdcache.v2 diff --git a/.vs/ApiPolo/v17/.futdcache.v2 b/.vs/ApiPolo/v17/.futdcache.v2 deleted file mode 100644 index 26b985d..0000000 Binary files a/.vs/ApiPolo/v17/.futdcache.v2 and /dev/null differ diff --git a/ApiPolo/Controllers/TestController.cs b/ApiPolo/Controllers/TestController.cs index c314ba1..906b954 100644 --- a/ApiPolo/Controllers/TestController.cs +++ b/ApiPolo/Controllers/TestController.cs @@ -2,14 +2,20 @@ using ApiPolo.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using System.IdentityModel.Tokens.Jwt; +using System.Text; +using static ApiPolo.Controllers.PoloController; namespace ApiPolo.Controllers { + /// public class TestController : Controller { //interfaccia con tutti i possibili dbset private readonly ITenantDbContextFactory _dbContextFactory; //DI con ITenantDbContextFactory + /// + private DbSet? _chiamate; public TestController(ITenantDbContextFactory dbContextFactory) { _dbContextFactory = dbContextFactory; @@ -131,6 +137,654 @@ namespace ApiPolo.Controllers } #endregion + #region utility + private string getClaimValueByToken(string token, string claimName) + { + string t = string.Empty; + + var handler = new JwtSecurityTokenHandler(); + var jwtSecurityToken = handler.ReadJwtToken(token); + if (jwtSecurityToken != null) + { + var id = jwtSecurityToken.Claims.First(claim => claim.Type == claimName).Value; + t = id; + } + return t; + } + private Chiamate_out fillChiamateOut(Chiamate i, string tenant) + { + Chiamate_out o = new Chiamate_out(); + o.chcodazi = i.chcodazi; + o.chserial = i.chserial; + o.chstato = i.chstato; + o.chtchiam = i.chtchiam; + + o.chdtapp = i.chdtapp; + o.choraaPI = i.choraaPI; + o.chminapi = i.chminapi; + o.chnote = i.chnote; + + o.chcodimp = i.chcodimp; + o.csdescr = i.csdescr; + o.antelefo = i.antelefo; + o.andescri = i.andescri; + o.imindiri1 = i.imindiri1; + + o.imindiri2 = i.imindiri2; + o.imindiri3 = i.imindiri3; + o.imindiri4 = i.imindiri4; + o.imindiri5 = i.imindiri5; + o.imlocali = i.imlocali; + o.imrefref = i.imrefref; + //costruisco il campo indirizzo + StringBuilder sb = new StringBuilder(); + + string chiamataIndStampa = string.Empty; + switch (tenant) + { + case Clienti.Marrocco: + #region marrocco + chiamataIndStampa = formattaIndirizzoStampaMarrocco(i); + #endregion + break; + case Clienti.Gitoga: + #region gitoga + chiamataIndStampa = formattaIndirizzoStampaMarrocco(i); + #endregion + break; + case Clienti.Lifta: + #region lifta + chiamataIndStampa = formattaIndirizzoStampaMarrocco(i); + #endregion + break; + case Clienti.Discovery: + #region Discovery + chiamataIndStampa = formattaIndirizzoStampaDiscovery(i); + #endregion + break; + case Clienti.Siet: + //ragione sociale cliente + sb.Append("SPETT.LE :"); + sb.Append(!string.IsNullOrEmpty(i.andescri) ? i.andescri + " " : string.Empty); + sb.Append("
"); + //indirizzo + sb.Append(!string.IsNullOrEmpty(i.imindiri1) ? i.imindiri1.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri2) ? i.imindiri2.Trim() + " " : string.Empty); + sb.Append(i.imindiri3 != null ? i.imindiri3.ToString() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri4) ? i.imindiri4.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri5) ? i.imindiri5.Trim() : string.Empty); + chiamataIndStampa = sb.ToString(); + + break; + default: + sb.Append("SPETT.LE :"); + if (!string.IsNullOrEmpty(i.andescri)) + { + sb.Append(!string.IsNullOrEmpty(i.andescri) ? i.andescri + " " : string.Empty); + sb.Append("
"); + } + + sb.Append(!string.IsNullOrEmpty(i.imindiri1) ? i.imindiri1.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri2) ? i.imindiri2.Trim() + " " : string.Empty); + sb.Append(i.imindiri3 != null ? i.imindiri3.ToString() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri4) ? i.imindiri4.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri5) ? i.imindiri5.Trim() : string.Empty); + chiamataIndStampa = sb.ToString(); + break; + } + o.indirizzo_stampa = chiamataIndStampa; + sb.Clear(); + + string chiamataItemList = string.Empty; + switch (tenant) + { + case Clienti.Marrocco: + #region marrocco + chiamataItemList = formattaItemChiamateMarrocco(i); + #endregion + break; + case Clienti.Gitoga: + #region gitoga + chiamataItemList = formattaItemChiamateMarrocco(i); + #endregion + break; + case Clienti.Lifta: + #region lifta + chiamataItemList = formattaItemChiamateMarrocco(i); + #endregion + break; + case Clienti.Tedesco: + #region Tedesco + chiamataItemList = formattaItemChiamateTedesco(i); + #endregion + break; + case Clienti.VT: + chiamataItemList = formattaItemChiamateVT(i); + break; + default: + #region default + sb.Append(!string.IsNullOrEmpty(i.imindiri1) ? i.imindiri1.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri2) ? i.imindiri2.Trim() + " " : string.Empty); + sb.Append(i.imindiri3 != null ? i.imindiri3.ToString() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri4) ? i.imindiri4.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imindiri5) ? i.imindiri5.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imcodcap) ? " " + i.imcodcap.Trim() + " " : string.Empty); + sb.Append(!string.IsNullOrEmpty(i.imlocali) ? " " + i.imlocali.Trim() + " " : string.Empty); + + if (!string.IsNullOrEmpty(i.chcodimp)) + { + sb.Append("
"); + sb.Append("Impianto : " + i.chcodimp.Trim()); + } + chiamataItemList = sb.ToString(); + break; + #endregion + } + o.impianto_list = chiamataItemList; + sb.Clear(); + + string rif_impianto = string.Empty; + switch (tenant) + { + case Clienti.Marrocco: + #region marrocco + rif_impianto = formattaRiferimentoImpiantoMarrocco(i); + #endregion + break; + case Clienti.Gitoga: + #region gitoga + rif_impianto = formattaRiferimentoImpiantoMarrocco(i); + #endregion + break; + case Clienti.Lifta: + #region lifta + rif_impianto = formattaRiferimentoImpiantoMarrocco(i); + #endregion + break; + case Clienti.Discovery: + #region discovery + rif_impianto = formattaRiferimentoImpiantoDiscovery(i); + #endregion + break; + case Clienti.Ferrari: + #region ferrari + rif_impianto = formattaRiferimentoImpiantoFerrari(i); + #endregion + break; + case Clienti.Siet: + #region SIET + sb.AppendLine("N. Impianto: " + i.chcodimp); + if (!string.IsNullOrEmpty(i.imubicaz)) + { + sb.AppendLine("Ubicazione: " + i.imubicaz); + } + if (!string.IsNullOrEmpty(i.chrifer)) + { + string comm = getCommessaSietBySerial(i.chrifer); + if (!string.IsNullOrEmpty(comm)) + { + sb.AppendLine("Commessa: " + comm); + } + + } + + rif_impianto = sb.ToString(); + #endregion + break; + default: + sb.AppendLine("N. Impianto: " + i.chcodimp); + if (!string.IsNullOrEmpty(i.imubicaz)) + sb.AppendLine("Ubicazione: " + i.imubicaz); + + rif_impianto = sb.ToString(); + break; + } + o.riferimento_impianto = rif_impianto; + sb.Clear(); + + o.imcodcap = i.imcodcap; + o.imcomune = i.imcomune; + o.improvin = i.improvin; + o.imcodnaz = i.imcodnaz; + + o.immatric = i.immatric; + o.imnumimp = i.imnumimp; + o.imubicaz = i.imubicaz; + + o.tcdescri = i.tcdescri; + + o.tccodice = i.tccodice; + o.ser_rapp_ic = i.ser_rapp_ic; + o.tipo_rapp_ic = i.tipo_rapp_ic; + o.ic = i.ic; + o.ser_rapp_rif = i.ser_rapp_rif; + + o.tipo_rapp_rif = i.tipo_rapp_rif; + o.rif = i.rif; + o.ser_rapp_chiu = i.ser_rapp_chiu; + o.tipo_rapp_chiu = i.tipo_rapp_chiu; + o.ser_buono_chiu = i.ser_buono_chiu; + + o.err_title = i.err_title; + o.err_detail = i.err_detail; + o.err_status_code = i.err_status_code; + o.ancodice = i.ancodice; + o.chiamata = i.chiamata; + o.spe_viaggio = i.spe_viaggio; + o.chnumero = i.chnumero; + + Dictionary dic = new Dictionary(); + switch (tenant) + { + case Clienti.Marrocco: + #region marrocco + dic.Add("Esercizio ", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("REF ", !string.IsNullOrEmpty(i.imrefref) ? i.imrefref : String.Empty); + dic.Add("Riferimento:", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Telefono rif.:", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + + #endregion + break; + + case Clienti.Gitoga: + #region gitoga + dic.Add("Esercizio ", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("REF ", !string.IsNullOrEmpty(i.imrefref) ? i.imrefref : String.Empty); + dic.Add("Riferimento:", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Telefono rif.:", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + #endregion + break; + + case Clienti.Lifta: + #region lifta + dic.Add("Esercizio ", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("REF ", !string.IsNullOrEmpty(i.imrefref) ? i.imrefref : String.Empty); + dic.Add("Riferimento:", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Telefono rif.:", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + #endregion + break; + + case Clienti.Ferrari: + #region ferrari + dic.Add("Esercizio", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("Tipo", !string.IsNullOrEmpty(i.chtipo) ? i.chtipo : String.Empty); + dic.Add("Numero chiamata", !string.IsNullOrEmpty(i.chnumero.ToString()) ? i.chnumero.ToString() : String.Empty); + dic.Add("Data chiamata", !string.IsNullOrEmpty(i.chdata.ToString()) ? i.chdata.ToString() : String.Empty); + dic.Add("Ora inserimento chiamata", !string.IsNullOrEmpty(i.chora.ToString()) ? i.chora.ToString() : String.Empty); + dic.Add("Min inserimento chiamata", !string.IsNullOrEmpty(i.chmin.ToString()) ? i.chmin.ToString() : String.Empty); + dic.Add("Operatore assegnazione", !string.IsNullOrEmpty(i.chopass.ToString()) ? i.chopass.ToString() : String.Empty); + dic.Add("Operatore chiusura", !string.IsNullOrEmpty(i.chopchi.ToString()) ? i.chopchi.ToString() : String.Empty); + dic.Add("Azienda impianto", !string.IsNullOrEmpty(i.chaziimp) ? i.chaziimp : String.Empty); + dic.Add("Ora appuntamento fine", !string.IsNullOrEmpty(i.choraapf.ToString()) ? i.choraapf.ToString() : String.Empty); + dic.Add("Min appuntamento fine", !string.IsNullOrEmpty(i.chminapf.ToString()) ? i.chminapf.ToString() : String.Empty); + dic.Add("Riferimento chiamata", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Riferimento telefono", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + dic.Add("Codice segnalazione", !string.IsNullOrEmpty(i.chcodseg) ? i.chcodseg : String.Empty); + dic.Add("Fermo impianto", !string.IsNullOrEmpty(i.chstopi) ? i.chstopi : String.Empty); + dic.Add("Data assegnazione chiamata", !string.IsNullOrEmpty(i.chdtass.ToString()) ? i.chdtass.ToString() : String.Empty); + dic.Add("Ora assegnazione chiamata", !string.IsNullOrEmpty(i.chorass.ToString()) ? i.chorass.ToString() : String.Empty); + dic.Add("Min assegnazione chiamata", !string.IsNullOrEmpty(i.chminass.ToString()) ? i.chminass.ToString() : String.Empty); + dic.Add("Data chiusura chiamata", !string.IsNullOrEmpty(i.chdtchi.ToString()) ? i.chdtchi.ToString() : String.Empty); + dic.Add("Ora chiusura chiamata", !string.IsNullOrEmpty(i.chorachi.ToString()) ? i.chorachi.ToString() : String.Empty); + dic.Add("Min chiusura chiamata", !string.IsNullOrEmpty(i.chminchi.ToString()) ? i.chminchi.ToString() : String.Empty); + dic.Add("Data inizio intervento", !string.IsNullOrEmpty(i.chdtlin.ToString()) ? i.chdtlin.ToString() : String.Empty); + dic.Add("Ora inizio intervento", !string.IsNullOrEmpty(i.chorali.ToString()) ? i.chorali.ToString() : String.Empty); + dic.Add("Min inizio intervento", !string.IsNullOrEmpty(i.chminli.ToString()) ? i.chminli.ToString() : String.Empty); + dic.Add("Data fine intervento", !string.IsNullOrEmpty(i.chdtlfi.ToString()) ? i.chdtlfi.ToString() : String.Empty); + + dic.Add("Ora fine intervento", !string.IsNullOrEmpty(i.choralf.ToString()) ? i.choralf.ToString() : String.Empty); + dic.Add("Min fine intervento", !string.IsNullOrEmpty(i.chminlf.ToString()) ? i.chminlf.ToString() : String.Empty); + dic.Add("Numero 1 rapportino futuro", !string.IsNullOrEmpty(i.chnrap1.ToString()) ? i.chnrap1.ToString() : String.Empty); + dic.Add("Serie 1 rapportino futuro", !string.IsNullOrEmpty(i.chsrap1) ? i.chsrap1 : String.Empty); + dic.Add("Numero 2 rapportino futuro", !string.IsNullOrEmpty(i.chnrap2.ToString()) ? i.chnrap2.ToString() : String.Empty); + dic.Add("Modalità raccolta chiamata", !string.IsNullOrEmpty(i.chmodrac) ? i.chmodrac : String.Empty); + dic.Add("Numero chiamata per impianto per anno", !string.IsNullOrEmpty(i.chprgann.ToString()) ? i.chprgann.ToString() : String.Empty); + dic.Add("Importo manodopera", !string.IsNullOrEmpty(i.chimpman.ToString()) ? i.chimpman.ToString() : String.Empty); + dic.Add("Percentuale manodopera", !string.IsNullOrEmpty(i.chperman.ToString()) ? i.chperman.ToString() : String.Empty); + dic.Add("Stampa manodopera", !string.IsNullOrEmpty(i.chflstim) ? i.chflstim : String.Empty); + dic.Add("Chiusura da remoto", !string.IsNullOrEmpty(i.chfleste) ? i.chfleste : String.Empty); + dic.Add("Riferimento seriale importazione", !string.IsNullOrEmpty(i.chserext) ? i.chserext : String.Empty); + dic.Add("Descrizione impianto", !string.IsNullOrEmpty(i.imdescri) ? i.imdescri : String.Empty); + dic.Add("Tipo impianto", !string.IsNullOrEmpty(i.imtipoim) ? i.imtipoim : String.Empty); + dic.Add("Matricola impianto ", !string.IsNullOrEmpty(i.immatric) ? i.immatric : String.Empty); + dic.Add("Numero impianto ", !string.IsNullOrEmpty(i.imnumimp) ? i.imnumimp : String.Empty); + dic.Add("Ultimo amministratore ", !string.IsNullOrEmpty(i.imultamm) ? i.imultamm : String.Empty); + dic.Add("Desc Ultimo amministratore ", !string.IsNullOrEmpty(i.imultdam) ? i.imultdam : String.Empty); + dic.Add("Telefono Ult. Amministratore", !string.IsNullOrEmpty(i.imulttam) ? i.imulttam : String.Empty); + + + dic.Add("Ubicazione impianto", !string.IsNullOrEmpty(i.imubicaz) ? i.imubicaz : String.Empty); + dic.Add("Zona manutenzione", !string.IsNullOrEmpty(i.imzonman) ? i.imzonman : String.Empty); + dic.Add("Pubblico/privato", !string.IsNullOrEmpty(i.imflpupr) ? i.imflpupr : String.Empty); + dic.Add("Zona chiamate", !string.IsNullOrEmpty(i.imzonchi) ? i.imzonchi : String.Empty); + dic.Add("Zona supervisione", !string.IsNullOrEmpty(i.imzonsup) ? i.imzonsup : String.Empty); + dic.Add("Data inizio manutenzione", i.imdainma != null ? i.imdainma.ToString() : String.Empty); + dic.Add("Data fine manutenzione", !string.IsNullOrEmpty(i.imdafima.ToString()) ? i.imdafima.ToString() : String.Empty); + dic.Add("Data costruzione", !string.IsNullOrEmpty(i.imdatcos.ToString()) ? i.imdatcos.ToString() : String.Empty); + dic.Add("Numero telesoccorso ", !string.IsNullOrEmpty(i.imteleso) ? i.imteleso : String.Empty); + dic.Add("Email cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Ultimo cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Codice cliente", !string.IsNullOrEmpty(i.ancodice) ? i.ancodice : String.Empty); + dic.Add("Tipo anagrafica", !string.IsNullOrEmpty(i.antipcon) ? i.antipcon : String.Empty); + #endregion + break; + case Clienti.Sicilia: + #region sicilia + dic.Add("Esercizio", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("Tipo", !string.IsNullOrEmpty(i.chtipo) ? i.chtipo : String.Empty); + dic.Add("Numero chiamata", !string.IsNullOrEmpty(i.chnumero.ToString()) ? i.chnumero.ToString() : String.Empty); + dic.Add("Data chiamata", !string.IsNullOrEmpty(i.chdata.ToString()) ? i.chdata.ToString() : String.Empty); + dic.Add("Ora inserimento chiamata", !string.IsNullOrEmpty(i.chora.ToString()) ? i.chora.ToString() : String.Empty); + dic.Add("Min inserimento chiamata", !string.IsNullOrEmpty(i.chmin.ToString()) ? i.chmin.ToString() : String.Empty); + dic.Add("Operatore assegnazione", !string.IsNullOrEmpty(i.chopass.ToString()) ? i.chopass.ToString() : String.Empty); + dic.Add("Operatore chiusura", !string.IsNullOrEmpty(i.chopchi.ToString()) ? i.chopchi.ToString() : String.Empty); + dic.Add("Azienda impianto", !string.IsNullOrEmpty(i.chaziimp) ? i.chaziimp : String.Empty); + dic.Add("Ora appuntamento fine", !string.IsNullOrEmpty(i.choraapf.ToString()) ? i.choraapf.ToString() : String.Empty); + dic.Add("Min appuntamento fine", !string.IsNullOrEmpty(i.chminapf.ToString()) ? i.chminapf.ToString() : String.Empty); + dic.Add("Riferimento chiamata", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Riferimento telefono", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + dic.Add("Codice segnalazione", !string.IsNullOrEmpty(i.chcodseg) ? i.chcodseg : String.Empty); + dic.Add("Fermo impianto", !string.IsNullOrEmpty(i.chstopi) ? i.chstopi : String.Empty); + dic.Add("Data assegnazione chiamata", !string.IsNullOrEmpty(i.chdtass.ToString()) ? i.chdtass.ToString() : String.Empty); + dic.Add("Ora assegnazione chiamata", !string.IsNullOrEmpty(i.chorass.ToString()) ? i.chorass.ToString() : String.Empty); + dic.Add("Min assegnazione chiamata", !string.IsNullOrEmpty(i.chminass.ToString()) ? i.chminass.ToString() : String.Empty); + dic.Add("Data chiusura chiamata", !string.IsNullOrEmpty(i.chdtchi.ToString()) ? i.chdtchi.ToString() : String.Empty); + dic.Add("Ora chiusura chiamata", !string.IsNullOrEmpty(i.chorachi.ToString()) ? i.chorachi.ToString() : String.Empty); + dic.Add("Min chiusura chiamata", !string.IsNullOrEmpty(i.chminchi.ToString()) ? i.chminchi.ToString() : String.Empty); + dic.Add("Data inizio intervento", !string.IsNullOrEmpty(i.chdtlin.ToString()) ? i.chdtlin.ToString() : String.Empty); + dic.Add("Ora inizio intervento", !string.IsNullOrEmpty(i.chorali.ToString()) ? i.chorali.ToString() : String.Empty); + dic.Add("Min inizio intervento", !string.IsNullOrEmpty(i.chminli.ToString()) ? i.chminli.ToString() : String.Empty); + dic.Add("Data fine intervento", !string.IsNullOrEmpty(i.chdtlfi.ToString()) ? i.chdtlfi.ToString() : String.Empty); + + dic.Add("Ora fine intervento", !string.IsNullOrEmpty(i.choralf.ToString()) ? i.choralf.ToString() : String.Empty); + dic.Add("Min fine intervento", !string.IsNullOrEmpty(i.chminlf.ToString()) ? i.chminlf.ToString() : String.Empty); + dic.Add("Numero 1 rapportino futuro", !string.IsNullOrEmpty(i.chnrap1.ToString()) ? i.chnrap1.ToString() : String.Empty); + dic.Add("Serie 1 rapportino futuro", !string.IsNullOrEmpty(i.chsrap1) ? i.chsrap1 : String.Empty); + dic.Add("Numero 2 rapportino futuro", !string.IsNullOrEmpty(i.chnrap2.ToString()) ? i.chnrap2.ToString() : String.Empty); + dic.Add("Modalità raccolta chiamata", !string.IsNullOrEmpty(i.chmodrac) ? i.chmodrac : String.Empty); + dic.Add("Numero chiamata per impianto per anno", !string.IsNullOrEmpty(i.chprgann.ToString()) ? i.chprgann.ToString() : String.Empty); + dic.Add("Importo manodopera", !string.IsNullOrEmpty(i.chimpman.ToString()) ? i.chimpman.ToString() : String.Empty); + dic.Add("Percentuale manodopera", !string.IsNullOrEmpty(i.chperman.ToString()) ? i.chperman.ToString() : String.Empty); + dic.Add("Stampa manodopera", !string.IsNullOrEmpty(i.chflstim) ? i.chflstim : String.Empty); + dic.Add("Chiusura da remoto", !string.IsNullOrEmpty(i.chfleste) ? i.chfleste : String.Empty); + dic.Add("Riferimento seriale importazione", !string.IsNullOrEmpty(i.chserext) ? i.chserext : String.Empty); + dic.Add("Descrizione impianto", !string.IsNullOrEmpty(i.imdescri) ? i.imdescri : String.Empty); + dic.Add("Tipo impianto", !string.IsNullOrEmpty(i.imtipoim) ? i.imtipoim : String.Empty); + dic.Add("Matricola impianto ", !string.IsNullOrEmpty(i.immatric) ? i.immatric : String.Empty); + dic.Add("Numero impianto ", !string.IsNullOrEmpty(i.imnumimp) ? i.imnumimp : String.Empty); + dic.Add("Ultimo amministratore ", !string.IsNullOrEmpty(i.imultamm) ? i.imultamm : String.Empty); + dic.Add("Desc Ultimo amministratore ", !string.IsNullOrEmpty(i.imultdam) ? i.imultdam : String.Empty); + dic.Add("Telefono Ult. Amministratore", !string.IsNullOrEmpty(i.imulttam) ? i.imulttam : String.Empty); + + + dic.Add("Ubicazione impianto", !string.IsNullOrEmpty(i.imubicaz) ? i.imubicaz : String.Empty); + dic.Add("Zona manutenzione", !string.IsNullOrEmpty(i.imzonman) ? i.imzonman : String.Empty); + dic.Add("Pubblico/privato", !string.IsNullOrEmpty(i.imflpupr) ? i.imflpupr : String.Empty); + dic.Add("Zona chiamate", !string.IsNullOrEmpty(i.imzonchi) ? i.imzonchi : String.Empty); + dic.Add("Zona supervisione", !string.IsNullOrEmpty(i.imzonsup) ? i.imzonsup : String.Empty); + dic.Add("Data inizio manutenzione", i.imdainma != null ? i.imdainma.ToString() : String.Empty); + dic.Add("Data fine manutenzione", !string.IsNullOrEmpty(i.imdafima.ToString()) ? i.imdafima.ToString() : String.Empty); + dic.Add("Data costruzione", !string.IsNullOrEmpty(i.imdatcos.ToString()) ? i.imdatcos.ToString() : String.Empty); + dic.Add("Numero telesoccorso ", !string.IsNullOrEmpty(i.imteleso) ? i.imteleso : String.Empty); + dic.Add("Email cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Ultimo cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Codice cliente", !string.IsNullOrEmpty(i.ancodice) ? i.ancodice : String.Empty); + dic.Add("Tipo anagrafica", !string.IsNullOrEmpty(i.antipcon) ? i.antipcon : String.Empty); + #endregion + + break; + case Clienti.Discovery: + #region discovery + dic.Add("Esercizio", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("Tipo", !string.IsNullOrEmpty(i.chtipo) ? i.chtipo : String.Empty); + dic.Add("Numero chiamata", !string.IsNullOrEmpty(i.chnumero.ToString()) ? i.chnumero.ToString() : String.Empty); + dic.Add("Data chiamata", !string.IsNullOrEmpty(i.chdata.ToString()) ? i.chdata.ToString() : String.Empty); + dic.Add("Ora inserimento chiamata", !string.IsNullOrEmpty(i.chora.ToString()) ? i.chora.ToString() : String.Empty); + dic.Add("Min inserimento chiamata", !string.IsNullOrEmpty(i.chmin.ToString()) ? i.chmin.ToString() : String.Empty); + dic.Add("Operatore assegnazione", !string.IsNullOrEmpty(i.chopass.ToString()) ? i.chopass.ToString() : String.Empty); + dic.Add("Operatore chiusura", !string.IsNullOrEmpty(i.chopchi.ToString()) ? i.chopchi.ToString() : String.Empty); + dic.Add("Azienda impianto", !string.IsNullOrEmpty(i.chaziimp) ? i.chaziimp : String.Empty); + dic.Add("Ora appuntamento fine", !string.IsNullOrEmpty(i.choraapf.ToString()) ? i.choraapf.ToString() : String.Empty); + dic.Add("Min appuntamento fine", !string.IsNullOrEmpty(i.chminapf.ToString()) ? i.chminapf.ToString() : String.Empty); + dic.Add("Riferimento chiamata", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Riferimento telefono", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + dic.Add("Codice segnalazione", !string.IsNullOrEmpty(i.chcodseg) ? i.chcodseg : String.Empty); + dic.Add("Fermo impianto", !string.IsNullOrEmpty(i.chstopi) ? i.chstopi : String.Empty); + dic.Add("Data assegnazione chiamata", !string.IsNullOrEmpty(i.chdtass.ToString()) ? i.chdtass.ToString() : String.Empty); + dic.Add("Ora assegnazione chiamata", !string.IsNullOrEmpty(i.chorass.ToString()) ? i.chorass.ToString() : String.Empty); + dic.Add("Min assegnazione chiamata", !string.IsNullOrEmpty(i.chminass.ToString()) ? i.chminass.ToString() : String.Empty); + dic.Add("Data chiusura chiamata", !string.IsNullOrEmpty(i.chdtchi.ToString()) ? i.chdtchi.ToString() : String.Empty); + dic.Add("Ora chiusura chiamata", !string.IsNullOrEmpty(i.chorachi.ToString()) ? i.chorachi.ToString() : String.Empty); + dic.Add("Min chiusura chiamata", !string.IsNullOrEmpty(i.chminchi.ToString()) ? i.chminchi.ToString() : String.Empty); + dic.Add("Data inizio intervento", !string.IsNullOrEmpty(i.chdtlin.ToString()) ? i.chdtlin.ToString() : String.Empty); + dic.Add("Ora inizio intervento", !string.IsNullOrEmpty(i.chorali.ToString()) ? i.chorali.ToString() : String.Empty); + dic.Add("Min inizio intervento", !string.IsNullOrEmpty(i.chminli.ToString()) ? i.chminli.ToString() : String.Empty); + dic.Add("Data fine intervento", !string.IsNullOrEmpty(i.chdtlfi.ToString()) ? i.chdtlfi.ToString() : String.Empty); + + dic.Add("Ora fine intervento", !string.IsNullOrEmpty(i.choralf.ToString()) ? i.choralf.ToString() : String.Empty); + dic.Add("Min fine intervento", !string.IsNullOrEmpty(i.chminlf.ToString()) ? i.chminlf.ToString() : String.Empty); + dic.Add("Numero 1 rapportino futuro", !string.IsNullOrEmpty(i.chnrap1.ToString()) ? i.chnrap1.ToString() : String.Empty); + dic.Add("Serie 1 rapportino futuro", !string.IsNullOrEmpty(i.chsrap1) ? i.chsrap1 : String.Empty); + dic.Add("Numero 2 rapportino futuro", !string.IsNullOrEmpty(i.chnrap2.ToString()) ? i.chnrap2.ToString() : String.Empty); + dic.Add("Modalità raccolta chiamata", !string.IsNullOrEmpty(i.chmodrac) ? i.chmodrac : String.Empty); + dic.Add("Numero chiamata per impianto per anno", !string.IsNullOrEmpty(i.chprgann.ToString()) ? i.chprgann.ToString() : String.Empty); + dic.Add("Importo manodopera", !string.IsNullOrEmpty(i.chimpman.ToString()) ? i.chimpman.ToString() : String.Empty); + dic.Add("Percentuale manodopera", !string.IsNullOrEmpty(i.chperman.ToString()) ? i.chperman.ToString() : String.Empty); + dic.Add("Stampa manodopera", !string.IsNullOrEmpty(i.chflstim) ? i.chflstim : String.Empty); + dic.Add("Chiusura da remoto", !string.IsNullOrEmpty(i.chfleste) ? i.chfleste : String.Empty); + dic.Add("Riferimento seriale importazione", !string.IsNullOrEmpty(i.chserext) ? i.chserext : String.Empty); + dic.Add("Descrizione impianto", !string.IsNullOrEmpty(i.imdescri) ? i.imdescri : String.Empty); + dic.Add("Tipo impianto", !string.IsNullOrEmpty(i.imtipoim) ? i.imtipoim : String.Empty); + dic.Add("Matricola impianto ", !string.IsNullOrEmpty(i.immatric) ? i.immatric : String.Empty); + dic.Add("Numero impianto ", !string.IsNullOrEmpty(i.imnumimp) ? i.imnumimp : String.Empty); + dic.Add("Ultimo amministratore ", !string.IsNullOrEmpty(i.imultamm) ? i.imultamm : String.Empty); + dic.Add("Desc Ultimo amministratore ", !string.IsNullOrEmpty(i.imultdam) ? i.imultdam : String.Empty); + dic.Add("Telefono Ult. Amministratore", !string.IsNullOrEmpty(i.imulttam) ? i.imulttam : String.Empty); + + + dic.Add("Ubicazione impianto", !string.IsNullOrEmpty(i.imubicaz) ? i.imubicaz : String.Empty); + dic.Add("Zona manutenzione", !string.IsNullOrEmpty(i.imzonman) ? i.imzonman : String.Empty); + dic.Add("Pubblico/privato", !string.IsNullOrEmpty(i.imflpupr) ? i.imflpupr : String.Empty); + dic.Add("Zona chiamate", !string.IsNullOrEmpty(i.imzonchi) ? i.imzonchi : String.Empty); + dic.Add("Zona supervisione", !string.IsNullOrEmpty(i.imzonsup) ? i.imzonsup : String.Empty); + dic.Add("Data inizio manutenzione", i.imdainma != null ? i.imdainma.ToString() : String.Empty); + dic.Add("Data fine manutenzione", !string.IsNullOrEmpty(i.imdafima.ToString()) ? i.imdafima.ToString() : String.Empty); + dic.Add("Data costruzione", !string.IsNullOrEmpty(i.imdatcos.ToString()) ? i.imdatcos.ToString() : String.Empty); + dic.Add("Numero telesoccorso ", !string.IsNullOrEmpty(i.imteleso) ? i.imteleso : String.Empty); + dic.Add("Email cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Ultimo cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Codice cliente", !string.IsNullOrEmpty(i.ancodice) ? i.ancodice : String.Empty); + dic.Add("Tipo anagrafica", !string.IsNullOrEmpty(i.antipcon) ? i.antipcon : String.Empty); + #endregion + break; + + case Clienti.Sarom: + #region Sarom + dic.Add("Esercizio", !string.IsNullOrEmpty(i.chcodese) ? i.chcodese : String.Empty); + dic.Add("Tipo", !string.IsNullOrEmpty(i.chtipo) ? i.chtipo : String.Empty); + dic.Add("Numero chiamata", !string.IsNullOrEmpty(i.chnumero.ToString()) ? i.chnumero.ToString() : String.Empty); + dic.Add("Data chiamata", !string.IsNullOrEmpty(i.chdata.ToString()) ? i.chdata.ToString() : String.Empty); + dic.Add("Ora inserimento chiamata", !string.IsNullOrEmpty(i.chora.ToString()) ? i.chora.ToString() : String.Empty); + dic.Add("Min inserimento chiamata", !string.IsNullOrEmpty(i.chmin.ToString()) ? i.chmin.ToString() : String.Empty); + dic.Add("Operatore assegnazione", !string.IsNullOrEmpty(i.chopass.ToString()) ? i.chopass.ToString() : String.Empty); + dic.Add("Operatore chiusura", !string.IsNullOrEmpty(i.chopchi.ToString()) ? i.chopchi.ToString() : String.Empty); + dic.Add("Azienda impianto", !string.IsNullOrEmpty(i.chaziimp) ? i.chaziimp : String.Empty); + dic.Add("Ora appuntamento fine", !string.IsNullOrEmpty(i.choraapf.ToString()) ? i.choraapf.ToString() : String.Empty); + dic.Add("Min appuntamento fine", !string.IsNullOrEmpty(i.chminapf.ToString()) ? i.chminapf.ToString() : String.Empty); + dic.Add("Riferimento chiamata", !string.IsNullOrEmpty(i.chrifer) ? i.chrifer : String.Empty); + dic.Add("Riferimento telefono", !string.IsNullOrEmpty(i.chtelef) ? i.chtelef : String.Empty); + dic.Add("Codice segnalazione", !string.IsNullOrEmpty(i.chcodseg) ? i.chcodseg : String.Empty); + dic.Add("Fermo impianto", !string.IsNullOrEmpty(i.chstopi) ? i.chstopi : String.Empty); + dic.Add("Data assegnazione chiamata", !string.IsNullOrEmpty(i.chdtass.ToString()) ? i.chdtass.ToString() : String.Empty); + dic.Add("Ora assegnazione chiamata", !string.IsNullOrEmpty(i.chorass.ToString()) ? i.chorass.ToString() : String.Empty); + dic.Add("Min assegnazione chiamata", !string.IsNullOrEmpty(i.chminass.ToString()) ? i.chminass.ToString() : String.Empty); + dic.Add("Data chiusura chiamata", !string.IsNullOrEmpty(i.chdtchi.ToString()) ? i.chdtchi.ToString() : String.Empty); + dic.Add("Ora chiusura chiamata", !string.IsNullOrEmpty(i.chorachi.ToString()) ? i.chorachi.ToString() : String.Empty); + dic.Add("Min chiusura chiamata", !string.IsNullOrEmpty(i.chminchi.ToString()) ? i.chminchi.ToString() : String.Empty); + dic.Add("Data inizio intervento", !string.IsNullOrEmpty(i.chdtlin.ToString()) ? i.chdtlin.ToString() : String.Empty); + dic.Add("Ora inizio intervento", !string.IsNullOrEmpty(i.chorali.ToString()) ? i.chorali.ToString() : String.Empty); + dic.Add("Min inizio intervento", !string.IsNullOrEmpty(i.chminli.ToString()) ? i.chminli.ToString() : String.Empty); + dic.Add("Data fine intervento", !string.IsNullOrEmpty(i.chdtlfi.ToString()) ? i.chdtlfi.ToString() : String.Empty); + + dic.Add("Ora fine intervento", !string.IsNullOrEmpty(i.choralf.ToString()) ? i.choralf.ToString() : String.Empty); + dic.Add("Min fine intervento", !string.IsNullOrEmpty(i.chminlf.ToString()) ? i.chminlf.ToString() : String.Empty); + dic.Add("Numero 1 rapportino futuro", !string.IsNullOrEmpty(i.chnrap1.ToString()) ? i.chnrap1.ToString() : String.Empty); + dic.Add("Serie 1 rapportino futuro", !string.IsNullOrEmpty(i.chsrap1) ? i.chsrap1 : String.Empty); + dic.Add("Numero 2 rapportino futuro", !string.IsNullOrEmpty(i.chnrap2.ToString()) ? i.chnrap2.ToString() : String.Empty); + dic.Add("Modalità raccolta chiamata", !string.IsNullOrEmpty(i.chmodrac) ? i.chmodrac : String.Empty); + dic.Add("Numero chiamata per impianto per anno", !string.IsNullOrEmpty(i.chprgann.ToString()) ? i.chprgann.ToString() : String.Empty); + dic.Add("Importo manodopera", !string.IsNullOrEmpty(i.chimpman.ToString()) ? i.chimpman.ToString() : String.Empty); + dic.Add("Percentuale manodopera", !string.IsNullOrEmpty(i.chperman.ToString()) ? i.chperman.ToString() : String.Empty); + dic.Add("Stampa manodopera", !string.IsNullOrEmpty(i.chflstim) ? i.chflstim : String.Empty); + dic.Add("Chiusura da remoto", !string.IsNullOrEmpty(i.chfleste) ? i.chfleste : String.Empty); + dic.Add("Riferimento seriale importazione", !string.IsNullOrEmpty(i.chserext) ? i.chserext : String.Empty); + dic.Add("Descrizione impianto", !string.IsNullOrEmpty(i.imdescri) ? i.imdescri : String.Empty); + dic.Add("Tipo impianto", !string.IsNullOrEmpty(i.imtipoim) ? i.imtipoim : String.Empty); + dic.Add("Matricola impianto ", !string.IsNullOrEmpty(i.immatric) ? i.immatric : String.Empty); + dic.Add("Numero impianto ", !string.IsNullOrEmpty(i.imnumimp) ? i.imnumimp : String.Empty); + dic.Add("Ultimo amministratore ", !string.IsNullOrEmpty(i.imultamm) ? i.imultamm : String.Empty); + dic.Add("Desc Ultimo amministratore ", !string.IsNullOrEmpty(i.imultdam) ? i.imultdam : String.Empty); + dic.Add("Telefono Ult. Amministratore", !string.IsNullOrEmpty(i.imulttam) ? i.imulttam : String.Empty); + + + dic.Add("Ubicazione impianto", !string.IsNullOrEmpty(i.imubicaz) ? i.imubicaz : String.Empty); + dic.Add("Zona manutenzione", !string.IsNullOrEmpty(i.imzonman) ? i.imzonman : String.Empty); + dic.Add("Pubblico/privato", !string.IsNullOrEmpty(i.imflpupr) ? i.imflpupr : String.Empty); + dic.Add("Zona chiamate", !string.IsNullOrEmpty(i.imzonchi) ? i.imzonchi : String.Empty); + dic.Add("Zona supervisione", !string.IsNullOrEmpty(i.imzonsup) ? i.imzonsup : String.Empty); + dic.Add("Data inizio manutenzione", i.imdainma != null ? i.imdainma.ToString() : String.Empty); + dic.Add("Data fine manutenzione", !string.IsNullOrEmpty(i.imdafima.ToString()) ? i.imdafima.ToString() : String.Empty); + dic.Add("Data costruzione", !string.IsNullOrEmpty(i.imdatcos.ToString()) ? i.imdatcos.ToString() : String.Empty); + dic.Add("Numero telesoccorso ", !string.IsNullOrEmpty(i.imteleso) ? i.imteleso : String.Empty); + dic.Add("Email cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Ultimo cliente", !string.IsNullOrEmpty(i.an_email) ? i.an_email : String.Empty); + dic.Add("Codice cliente", !string.IsNullOrEmpty(i.ancodice) ? i.ancodice : String.Empty); + dic.Add("Tipo anagrafica", !string.IsNullOrEmpty(i.antipcon) ? i.antipcon : String.Empty); + #endregion + break; + + default: + + break; + } + o.altri = dic; + + o.imazirif = i.imazirif; + o.imrefref = i.imrefref; + return o; + } + private string getCommessaSietBySerial(string seriale) + { + string commessa = string.Empty; + + try + { + //_commDescSiet = _Siet_commDesc.Commdesc; + //var c = _commDescSiet.Where(c => c.laserial.Equals(seriale)).First(); + //if (c != null && !string.IsNullOrEmpty(c.lacodcom)) + //{ + // commessa = c.lacodcom.Trim(); + // if (!string.IsNullOrEmpty(c.lacodcen)) + // { + // commessa = commessa + " - " + c.lacodcen.Trim(); + // } + //} + } + catch + { + Console.WriteLine(string.Format("*********** {1} Errore Chiamata al metodo getCommessaSietBySerial: seriale:{0} ", seriale, DateTime.Now.ToString())); + } + + return commessa; + } + #endregion + /// chiamatetest + [HttpGet("chiamatetest")] + public async Task>> chiamate(string token) + { + try + { + List ilist = new List(); + string ten = getClaimValueByToken(token, "tenant"); + string ten2 = getClaimValueByToken(token, "tenant2"); + string tenOut = getClaimValueByToken(token, "tenant"); + string tecnico = getClaimValueByToken(token, "tccodice"); + string tenConf = getClaimValueByToken(token, "tenantConfigurazioni"); + if (string.IsNullOrEmpty(ten)) + { + ten = tenConf; + } + + _chiamate = getChiamateByTenant(ten); + + + var calltec = await _chiamate.Where( + t => t.tccodice == tecnico + && t.chcodazi == ten + ).OrderByDescending(t => t.chdtapp).ToListAsync(); + + foreach (Chiamate ch in calltec) + { + Chiamate_out o = new Chiamate_out(); + + o = fillChiamateOut(ch, ten); + + + ilist.Add(o); + } + // cerco le chiamate che devo fare per sostituzioni SE funzione abilitata + //bool cerca_sostituzioni = false; + //cerca_sostituzioni = checkSostituzioneAbilitata(ten); + //if (cerca_sostituzioni) + //{ + // //step 1 : trovo tutte le MIE sostituzioni + // _sostituzione = getSostituzioneByTenant(ten); + // var s = _sostituzione.Where(t => t.tscodazi.Equals(ten) && t.tscodsos.Trim().Equals(tecnico)); + // foreach (Sostituzione ss in s) + // { + // string tecnico_sostituito = string.Empty; + // tecnico_sostituito = ss.tscodtec != null ? ss.tscodtec : string.Empty; + + // //2023-03-13: cancellato il filtro sulla zona perchè il tecnico che sostituisce spesso è di un'altra zona + // //string zona = string.Empty; + // //zona = ss.tscodzon != null ? ss.tscodzon : "zonavuota"; + + // //step 2 : trovo tutte le chiamate del tecnico che sto sostitutendo e le aggiungo alla mie + // var calltecSost = await _chiamate.Where( + // t => t.tccodice == tecnico_sostituito + // && t.chcodazi == ten + // //&& t.imzonchi.Equals(zona) + // ).OrderByDescending(t => t.chdtapp).ToListAsync(); + + // foreach (Chiamate ch in calltecSost) + // { + // Chiamate_out o = new Chiamate_out(); + // if (tenOut.Equals(Clienti.VT)) + // { + // o = fillChiamateOutVT(ch, ten); + // } + // else + // { + // o = fillChiamateOut(ch, ten); + // } + + // ilist.Add(o); + // } + // } + //} + + IEnumerable enumerable = ilist as IEnumerable; + + //return StatusCode(StatusCodes.Status200OK, enumerable.Take(100)); + return StatusCode(StatusCodes.Status200OK, enumerable); + } + catch (Exception ex) + { + string err = "Errore: " + ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, err); + } + } + } diff --git a/ApiPolo/Data/Maras_DbContext.cs b/ApiPolo/Data/Maras_DbContext.cs index 7c67cfb..b88f741 100644 --- a/ApiPolo/Data/Maras_DbContext.cs +++ b/ApiPolo/Data/Maras_DbContext.cs @@ -1,9 +1,11 @@ using ApiPolo.Interfaces; using ApiPolo.Models; +using ApiPolo.Models.Security_dbcontext; using Microsoft.EntityFrameworkCore; namespace ApiPolo.Data { + /// public class Maras_DbContext : DbContext,ITenantDbContext { #region PROPERTIES @@ -55,11 +57,14 @@ namespace ApiPolo.Data public DbSet? Commesse { get; set; } #endregion + /// + public Maras_DbContext(DbContextOptions options) : base(options) + { + } - + /// protected override void OnModelCreating(ModelBuilder modelBuilder) { - void TryConfigureEntity(Action configure, string entityName) { try diff --git a/ApiPolo/Data/Marro_DbContext.cs b/ApiPolo/Data/Marro_DbContext.cs new file mode 100644 index 0000000..1bda6c2 --- /dev/null +++ b/ApiPolo/Data/Marro_DbContext.cs @@ -0,0 +1,176 @@ +using ApiPolo.Interfaces; +using ApiPolo.Models; +using ApiPolo.Models.Security_dbcontext; +using Microsoft.EntityFrameworkCore; + +namespace ApiPolo.Data +{ + /// + public class Marro_DbContext : DbContext,ITenantDbContext + { + #region PROPERTIES + public DbSet? Causali { get; set; } + + public DbSet? Chiusure { get; set; } + + public DbSet? Azi { get; set; } + + public DbSet? ccci { get; set; } + + public DbSet? ccciWiev { get; set; } + + public DbSet? Chiamate { get; set; } + + public DbSet? Clienti { get; set; } + + public DbSet? Componen { get; set; } // IN CONFLITTO CON Compo_Impia + + //public DbSet? Componen { get; set; } //CAMBIARE NOME!!! + + public DbSet? Impia { get; set; } + + public DbSet? Mag { get; set; } + + public DbSet? Magaz { get; set; } + + public DbSet? Manutenzioni { get; set; } + + public DbSet? Pagamenti { get; set; } + + public DbSet? Prese { get; set; } + + public DbSet? Rapps { get; set; } + + public DbSet? rapp { get; set; } + + public DbSet? Sost { get; set; } + + public DbSet? Saldi { get; set; } + + public DbSet? StoRapp { get; set; } + + public DbSet? Tecnici { get; set; } + public DbSet? StoImp { get; set; } + + public DbSet? Timbr { get; set; } + + public DbSet? Commesse { get; set; } + #endregion + + /// + public Marro_DbContext(DbContextOptions options) : base(options) + { + } + + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + void TryConfigureEntity(Action configure, string entityName) + { + try + { + configure(modelBuilder); + } + catch (Exception ex) + { + Console.WriteLine($"Warning: Skipping entity '{entityName}' due to error: {ex.Message}"); + } + } + + TryConfigureEntity(mb => mb.Entity().ToView("API_CAUS_RAPP"), "API_CAUS_RAPP"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_CHIUSURE"), "API_CHIUSURE"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("PIAZIRIF"); + mb.Entity().HasKey(table => new + { + table.piazihoc, + table.picodtec, + table.pirifazi + }); + }, "PIAZIRIF"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("PIASSCHIU"); + mb.Entity().HasKey(table => new + { + table.picodazi, + table.picodint, + table.picodchi + }); + }, "PIASSCHIU"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_ASSCHIU"), "API_ASSCHIU"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_CHIAMATE"), "API_CHIAMATE"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_CLIENTI"), "API_CLIENTI"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("DISCOMICOMIMP"); + mb.Entity().HasKey(table => new + { + table.cocodimp, + table.cprownum, + table.cocodazi + }); + }, "DISCOMICOMIMP"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_MICOMIMP"), "API_MICOMIMP"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_IMPIANTI"), "API_IMPIANTI"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("DISCOMAG_NEW"); + mb.Entity().HasKey(table => new + { + table.seriale_rapportino, + table.riga + }); + }, "DISCOMAG_NEW"); + + TryConfigureEntity(mb => mb.Entity().ToTable("DISCOMAGAZZIN"), "DISCOMAGAZZIN"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_MANPROG"), "API_MANPROG"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_PAGAMENTI"), "API_PAGAMENTI"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("PIPRESA"); + mb.Entity().HasKey(table => new + { + table.picodazi, + table.pimpianto, + table.picodint, + table.pidatman + }); + }, "PIPRESA"); + + TryConfigureEntity(mb => mb.Entity().ToTable("RAPP_NEW"), "RAPP_NEW"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_RAPPORTINI"), "API_RAPPORTINI"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_SALDIART_PREZZI"), "API_SALDIART_PREZZI"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_SOSTITUZIONI"), "API_SOSTITUZIONI"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_STO_RAPP"), "API_STO_RAPP"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_TECNICI"), "API_TECNICI"); + + TryConfigureEntity(mb => mb.Entity().ToTable("TIMBRATURE"), "TIMBRATURE"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_COMMESSE"), "API_COMMESSE"); + + TryConfigureEntity(mb => mb.Entity().ToView("API_STO_IMP"), "API_STO_IMP"); + + + } + } +} diff --git a/ApiPolo/Interfaces/TenantDbContextFactory.cs b/ApiPolo/Interfaces/TenantDbContextFactory.cs index 1c18d20..aed0627 100644 --- a/ApiPolo/Interfaces/TenantDbContextFactory.cs +++ b/ApiPolo/Interfaces/TenantDbContextFactory.cs @@ -1,29 +1,27 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using ApiPolo.Data; using ApiPolo.Interfaces; -using System; -using System.Collections.Generic; using static ApiPolo.Controllers.PoloController; -using ApiPolo.Data; -namespace ApiPolo.Services +public class TenantDbContextFactory : ITenantDbContextFactory { - public class TenantDbContextFactory : ITenantDbContextFactory + private readonly IServiceProvider _serviceProvider; + + public TenantDbContextFactory(IServiceProvider serviceProvider) { - private readonly IServiceProvider _serviceProvider; + _serviceProvider = serviceProvider; + } - public TenantDbContextFactory(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - - public ITenantDbContext GetDbContext(string tenant) + public ITenantDbContext GetDbContext(string tenant) + { + // Create a scope to resolve DbContext + using (var scope = _serviceProvider.CreateScope()) { return tenant switch { - Clienti.Maras => _serviceProvider.GetRequiredService(), + Clienti.Maras => scope.ServiceProvider.GetRequiredService(), + Clienti.Marrocco => scope.ServiceProvider.GetRequiredService(), // Add other tenants as needed - // Clienti.AnotherTenant => _serviceProvider.GetRequiredService(), + // Clienti.AnotherTenant => scope.ServiceProvider.GetRequiredService(), _ => throw new KeyNotFoundException($"No DbContext found for tenant: {tenant}") }; } diff --git a/ApiPolo/Startup.cs b/ApiPolo/Startup.cs index 9e7c94b..f432278 100644 --- a/ApiPolo/Startup.cs +++ b/ApiPolo/Startup.cs @@ -1015,12 +1015,19 @@ namespace ApiPolo )); #endregion + + //TEST + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("MARAS") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("MARRO") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); + // FACTORY MUTI-TENANT - services.AddSingleton(); + services.AddScoped(); services.AddSwaggerGen(gen =>