From 81c6a75fa7f172622f0290c929478a4c1e79837c Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Thu, 27 Mar 2025 11:50:23 +0100 Subject: [PATCH] refactorining per inserimento chiamata da app --- ApiPolo/Controllers/PoloController.cs | 569 ++++--------------------- ApiPolo/Data/Maras_DbContext.cs | 1 + ApiPolo/Data/TenantDbContext.cs | 12 + ApiPolo/Interfaces/ITenantDbContext.cs | 2 +- ApiPolo/Service.cs | 63 ++- 5 files changed, 164 insertions(+), 483 deletions(-) diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index 116ef7e..6db2cb9 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -1388,6 +1388,11 @@ namespace ApiPolo.Controllers var dbContext = _dbContextFactory.GetDbContext(tenant); return dbContext.Sost; // Use Set() to handle different DbContexts } + private DbSet getChiamateTableByTenant(string tenant) + { + var dbContext = _dbContextFactory.GetDbContext(tenant); + return dbContext.ChiamateTables; // Use Set() to handle different DbContexts + } //private DbSet getComponentiByTenant(string tenant) //{ // var dbContext = _dbContextFactory.GetDbContext(tenant); @@ -2726,48 +2731,20 @@ namespace ApiPolo.Controllers switch (tenant) { - case Clienti.Discovery: - new_serial = suffClienti.Discovery + new_serial; - break; - case Clienti.Marrocco: - new_serial = suffClienti.Marrocco + new_serial; - break; - case Clienti.Ferrari: - new_serial = suffClienti.Ferrari + new_serial; - break; - case Clienti.Sicilia: - new_serial = suffClienti.Sicilia + new_serial; - break; - case Clienti.Sarom: - new_serial = suffClienti.Sarom + new_serial; - break; - case Clienti.Sinergo: - new_serial = suffClienti.Sinergo + new_serial; - break; - case Clienti.Gitoga: - new_serial = suffClienti.Gitoga + new_serial; - break; - case Clienti.Lifta: - new_serial = suffClienti.Lifta + new_serial; - break; - case Clienti.Siet: - new_serial = suffClienti.Siet + new_serial; - break; case Clienti.PMS: new_serial = suffClienti.PMS + new_serial; break; - case Clienti.VT: - new_serial = suffClienti.VT + new_serial; - break; + case Clienti.LW: new_serial = suffClienti.LW + new_serial; break; - case Clienti.Tedesco: - new_serial = suffClienti.Tedes + new_serial; - break; + case Clienti.Syscom: new_serial = suffClienti.Sys + new_serial; break; + case Clienti.Maras: + new_serial = suffClienti.Mara + new_serial; + break; } return new_serial; } @@ -5606,6 +5583,7 @@ namespace ApiPolo.Controllers newSerial = await getSeriale(token); Rapp_New r = await fillRappNewByInput(model, token, newSerial, _confLette); _service.AddRappNewToDbAsync(ten, r); + System.Threading.Thread.Sleep(1000); calltec = await getChiamataBySerial(model.seriale_chiamata, token); calltec_out = fillChiamateOut(calltec, ten); @@ -5648,12 +5626,13 @@ namespace ApiPolo.Controllers try { if (await checkChiamataRifiutata(ten, model.seriale_chiamata, TipoRapportino.PresaInCarico,ten2) == 0) - { + { _confLette = await readConf(tenConf); string newSerial = string.Empty; newSerial = await getSeriale(token); Rapp_New r = await fillRappNewRifiutoByInput(model, token, newSerial, _confLette); _service.AddRappNewToDbAsync(ten, r); + System.Threading.Thread.Sleep(1000); calltec = await getChiamataBySerial(model.seriale_chiamata, token); calltec_out = fillChiamateOut(calltec, ten); @@ -5702,6 +5681,7 @@ namespace ApiPolo.Controllers newSerial = await getSeriale(token); Rapp_New r = await fillRappNewChiudiByInput(model, token, newSerial, _confLette); _service.AddRappNewToDbAsync(ten, r); + System.Threading.Thread.Sleep(1000); calltec = await getChiamataBySerial(r.seriale_chiamata, token); calltec_out = fillChiamateOut(calltec, ten); @@ -5745,137 +5725,13 @@ namespace ApiPolo.Controllers Chiamate_out calltec_out = new Chiamate_out(); Rapp_New r = null; - - try { if ((r=await checkChiamataDaRilasciare (ten, model.seriale_rapportino, TipoRapportino.PresaInCarico, ten2))!=null) { _service.RemoveRappNewToDbAsync(ten, r); - /* - switch (ten) - { - case Clienti.Marrocco: - using (var transaction = _Marro_rapp.Database.BeginTransaction()) - { - _Marro_rapp.Rapps.Remove(r); - await _Marro_rapp.SaveChangesAsync(); - transaction.Commit(); - } - - break; - case Clienti.Ferrari: - using (var transaction = _Ferra_rapp.Database.BeginTransaction()) - { - _Ferra_rapp.Rapps.Remove(r); - await _Ferra_rapp.SaveChangesAsync(); - transaction.Commit(); - } - - break; - case Clienti.Sarom: - using (var transaction = _Sarom_rapp.Database.BeginTransaction()) - { - _Sarom_rapp.Rapps.Remove(r); - await _Sarom_rapp.SaveChangesAsync(); - transaction.Commit(); - } - - break; - case Clienti.Gitoga: - using (var transactionGit = _Gitoga_rapp.Database.BeginTransaction()) - { - _Gitoga_rapp.Rapps.Remove(r); - await _Gitoga_rapp.SaveChangesAsync(); - transactionGit.Commit(); - } - - break; - case Clienti.Lifta: - using (var transactionLif = _Lifta_rapp.Database.BeginTransaction()) - { - _Lifta_rapp.Rapps.Remove(r); - await _Lifta_rapp.SaveChangesAsync(); - transactionLif.Commit(); - } - - break; - - case Clienti.Sicilia: - using (var transaction = _Sicilia_rapp.Database.BeginTransaction()) - { - _Sicilia_rapp.Rapps.Remove(r); - await _Sicilia_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Discovery: - - using (var transaction = _Disco_rapp.Database.BeginTransaction()) - { - _Disco_rapp.Rapps.Remove(r); - await _Disco_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Siet: - - using (var transaction = _Siet_rapp.Database.BeginTransaction()) - { - _Siet_rapp.Rapps.Remove(r); - await _Siet_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.PMS: - - using (var transaction = _Pms_rapp.Database.BeginTransaction()) - { - _Pms_rapp.Rapps.Remove(r); - await _Pms_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.VT: - using (var transactionVT = _VT_rapptable.Database.BeginTransaction()) - { - _VT_rapptable.Rapps.Remove(r); - await _VT_rapptable.SaveChangesAsync(); - transactionVT.Commit(); - } - break; - case Clienti.LW: - - using (var transaction = _LW_rapp.Database.BeginTransaction()) - { - _LW_rapp.Rapps.Remove(r); - await _LW_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Tedesco : - - using (var transaction = _Tedes_rapp.Database.BeginTransaction()) - { - _Tedes_rapp.Rapps.Remove(r); - await _Tedes_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Syscom: - - using (var transaction = _Sys_rapp.Database.BeginTransaction()) - { - _Sys_rapp.Rapps.Remove(r); - await _Sys_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - default: - break; - } - */ + System.Threading.Thread.Sleep(1000); calltec = await getChiamataBySerial(r.seriale_chiamata, token); calltec_out = fillChiamateOut(calltec, ten); calltec_out.err_status_code = StatiRisposta.Ok; @@ -7543,8 +7399,7 @@ namespace ApiPolo.Controllers [Route("file/upload")] public async Task OnPostUpload2Async(IFormFile files, string token, string nomefile) { - - + string ten = getClaimValueByToken(token, "tenant"); string ten2 = getClaimValueByToken(token, "tenant2"); string tenConf = getClaimValueByToken(token, "tenantConfigurazioni"); @@ -7555,19 +7410,10 @@ namespace ApiPolo.Controllers ten = tenConf; } string fileName = string.Empty; - - //Console.WriteLine(string.Format("*********** {2} metodo chiudi: tenant:{0} tenant2: {1} tenantConf: {5} buono: {3} tecnico:{4} ", ten, ten2, DateTime.Now.ToString(), r.ser_buono, r.codice_tecnico,tenConf)); + Console.WriteLine(string.Format("*********** {2} INIZIO Chiamata al metodo upload: tenant:{0} tenant2: {3} tenantConf: {4} file: {1} tecnico:{5}", ten, nomefile, DateTime.Now.ToString(),ten2,tenConf, tecnico)); + _confLette = await readConf(tenConf); - if (ten.Equals(Clienti.VT)) - { - //ten2= getClaimValueByToken(token, "tenant2"); - _confLette = await readConf(ten2); - } - else - { - _confLette = await readConf(tenConf); - } try { @@ -7589,97 +7435,6 @@ namespace ApiPolo.Controllers switch (ten) { - case Clienti.Marrocco: - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - FtpSend(url, usr, pwd, files); - - break; - case Clienti.Gitoga: - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - FtpSend(url, usr, pwd, files); - - break; - case Clienti.Lifta: - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - FtpSend(url, usr, pwd, files); - - break; - - case Clienti.Ferrari: - ip = _confLette.ftp_url!=null ? _confLette.ftp_url : string.Empty; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - port = _confLette.ftp_port != null ? _confLette.ftp_port : 0; - - FileUploadSFTP(files,ip,usr,pwd, port,fileName); - - break; - case Clienti.Sarom: - ip = _confLette.ftp_url != null ? _confLette.ftp_url : string.Empty; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - port = _confLette.ftp_port != null ? _confLette.ftp_port : 0; - - FileUploadSFTP(files, ip, usr, pwd, port, fileName); - - break; - case Clienti.Sicilia: - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - FtpSend(url, usr, pwd, files); - - break; - case Clienti.Discovery: - - //ip = _confLette.ftp_url != null ? _confLette.ftp_url : string.Empty; - //usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - //pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - //port = _confLette.ftp_port != null ? _confLette.ftp_port : 0; - //FileUploadSFTP(files, ip, usr, pwd, port, fileName); - - - //url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - port = _confLette.ftp_port != null ? _confLette.ftp_port : 0; - - //ftp://discoverylift.dyndns.org:21/test.jpg; - url = string.Format("{0}:{1}/{2}", _confLette.ftp_url, port, fileName); - FtpSend(url, usr, pwd, files); - break; - case Clienti.Siet: - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - FtpSend(url, usr, pwd, files); - break; - case Clienti.PMS: - //url = _confLette.ftp_url + fileName; - //usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - //pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - //port = _confLette.ftp_port != null ? _confLette.ftp_port : 0; - //ip = _confLette.ftp_url != null ? _confLette.ftp_url : string.Empty; - //FileUploadSFTP(files, ip, usr, pwd, port, fileName); - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - - FtpSend(url, usr, pwd, files); - string _esito = CheckFtp(url, usr, pwd); - if(_esito.Equals("KO")) - { - throw new Exception("Buono non depositato !!"+url); - } - - break; - case Clienti.LW: #region inserimento tabella @@ -7708,13 +7463,6 @@ namespace ApiPolo.Controllers #endregion break; - case Clienti.Tedesco: - - url = _confLette.ftp_url + fileName; - usr = _confLette.ftp_usr != null ? _confLette.ftp_usr : string.Empty; - pwd = _confLette.ftp_pwd != null ? _confLette.ftp_pwd : string.Empty; - FtpSend(url, usr, pwd, files); - break; case Clienti.Syscom: #region inserimento tabella @@ -7762,7 +7510,7 @@ namespace ApiPolo.Controllers sb.AppendLine(ex.InnerException.Message); } errMsg = sb.ToString(); - //Console.WriteLine(string.Format("*********** {2} ERRORE metodo upload: tenant:{0} file: {1} ==> {3}", ten, nomefile, DateTime.Now.ToString(),errMsg)); + Console.WriteLine(string.Format("*********** {2} ERRORE metodo upload: tenant:{0} tenant2: {3} tenantConf: {4} file: {1} tecnico:{5} ==> {6}", ten, nomefile, DateTime.Now.ToString(), ten2, tenConf, tecnico, errMsg)); return StatusCode(StatusCodes.Status500InternalServerError, "Error: "+errMsg); } @@ -11657,7 +11405,7 @@ namespace ApiPolo.Controllers ten = tenConf; } - //Console.WriteLine(string.Format("*********** {2} INIZIO Chiamata al metodo ricerca_commessa_impianto2: tipo:{0} file: {1} ", ten, tipo, DateTime.Now.ToString())); + //Radio Commessa, tipo 1 , campi cli e comm //Radio Cliente, tipo 2, campi cli //Radio Impianto, tipo 3, campi codimp e indirizzoImp @@ -11839,47 +11587,6 @@ namespace ApiPolo.Controllers //lettura seriali e progressivi switch (ten) { - case Clienti.Sicilia: - cpwarnNumChiamataDecimal = await leggiCpwarnProgDecimal(ten, "prog\\NUMCHI\\", esercizio); - progChiamata = Convert.ToString(cpwarnNumChiamataDecimal.autonum); - tablecodeProg = cpwarnNumChiamataDecimal.tablecode; - warncodeProg = cpwarnNumChiamataDecimal.warncode; - progressivoLetto = cpwarnNumChiamataDecimal.autonum; - - cpwarnSerialeDecimal = await leggiCpwarnSerialeDecimal(ten, "prog\\SERCHI\\"); - serialeChiamata = Convert.ToString(cpwarnSerialeDecimal.autonum); - tablecodeSer = cpwarnSerialeDecimal.tablecode; - warncodeSer = cpwarnSerialeDecimal.warncode; - serialeLetto = cpwarnSerialeDecimal.autonum; - - - break; - - case Clienti.Marrocco: - case Clienti.Gitoga: - case Clienti.Lifta: - cpwarnNumChiamata = await leggiCpwarnProg(ten, "prog\\NUMCHI\\", esercizio); - progChiamata = Convert.ToString(cpwarnNumChiamata.autonum); - tablecodeProg = cpwarnNumChiamata.tablecode; - warncodeProg = cpwarnNumChiamata.warncode; - - //_chiamateser = getChiamateSerialeByTenant(ten); - //serialeChiamata = _chiamateser.First().pinumero; - break; - - case Clienti.Siet: - - cpwarnNumChiamata = await leggiCpwarnProg(ten, "prog\\NUMCHI\\", esercizio); - progChiamata = Convert.ToString(cpwarnNumChiamata.autonum); - tablecodeProg = cpwarnNumChiamata.tablecode; - warncodeProg = cpwarnNumChiamata.warncode; - - cpwarnSeriale = await leggiCpwarnSeriale(ten, "prog\\SERCHI\\"); - serialeChiamata = Convert.ToString(cpwarnSeriale.autonum); - tablecodeSer = cpwarnSeriale.tablecode; - warncodeSer = cpwarnSeriale.warncode; - - break; case Clienti.PMS: cpwarnNumChiamataDecimal = await leggiCpwarnProgDecimal(ten, "prog\\NUMCHI\\", esercizio); @@ -11911,7 +11618,7 @@ namespace ApiPolo.Controllers serialeLetto = cpwarnSerialeDecimal.autonum; break; - case Clienti.Tedesco: + case Clienti.Syscom: cpwarnNumChiamataDecimal = await leggiCpwarnProgDecimal(ten, "prog\\NUMCHI\\", esercizio); progChiamata = Convert.ToString(cpwarnNumChiamataDecimal.autonum); tablecodeProg = cpwarnNumChiamataDecimal.tablecode; @@ -11925,8 +11632,7 @@ namespace ApiPolo.Controllers serialeLetto = cpwarnSerialeDecimal.autonum; break; - - case Clienti.Syscom: + case Clienti.Maras: cpwarnNumChiamataDecimal = await leggiCpwarnProgDecimal(ten, "prog\\NUMCHI\\", esercizio); progChiamata = Convert.ToString(cpwarnNumChiamataDecimal.autonum); tablecodeProg = cpwarnNumChiamataDecimal.tablecode; @@ -11951,80 +11657,58 @@ namespace ApiPolo.Controllers serial_comm = await leggiSerialeByCodCommessa(ten, codice_commessa); } - //tOut.uscita = await inserimentoChiamata2(ten, tecnico, codimp, serialeChiamata, progChiamata, serial_comm,ten); tOut.uscita = await inserimentoChiamata2(tenConf, tecnico, codimp, serialeChiamata, progChiamata, serial_comm, ten, tenConf); - - - + //aggiornamento seriali e progressivi string serialeUpdate = string.Empty; float numeroUpdate = 0; - switch (ten) - { - case Clienti.Sicilia: - //aggiornamento tabella con decimal - serialeUpdate = tOut.uscita.chserial; - serialeLetto = serialeLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); + serialeUpdate = tOut.uscita.chserial; + serialeLetto = serialeLetto + 1; + tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); - progressivoLetto = progressivoLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); - break; - case Clienti.Marrocco: - case Clienti.Gitoga: - case Clienti.Lifta: - serialeUpdate = tOut.uscita.chserial; - tOut.chiaser_Out = await aggiornaSeriale(ten, serialeUpdate); + progressivoLetto = progressivoLetto + 1; + tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); - numeroUpdate = (float)tOut.uscita.chnumero; - tOut.prog_Out = await aggiornaprogressivo(ten, numeroUpdate, tablecodeProg, warncodeProg); - break; - case Clienti.Siet: + //switch (ten) + //{ - serialeUpdate = tOut.uscita.chserial; - decimal ss = Convert.ToDecimal(serialeUpdate); - float zz = (float)ss; - tOut.prog_Out = await aggiornaprogressivo(ten, zz, tablecodeSer, warncodeSer); + // case Clienti.PMS: - numeroUpdate = (float)tOut.uscita.chnumero; - tOut.prog_Out = await aggiornaprogressivo(ten, numeroUpdate, tablecodeProg, warncodeProg); - break; - case Clienti.PMS: + // serialeUpdate = tOut.uscita.chserial; + // serialeLetto = serialeLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); - serialeUpdate = tOut.uscita.chserial; - serialeLetto = serialeLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); + // progressivoLetto = progressivoLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); + // break; + // case Clienti.LW: + // serialeUpdate = tOut.uscita.chserial; + // serialeLetto = serialeLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); - progressivoLetto = progressivoLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); - break; - case Clienti.LW: - serialeUpdate = tOut.uscita.chserial; - serialeLetto = serialeLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); + // progressivoLetto = progressivoLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); + // break; - progressivoLetto = progressivoLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); - break; - case Clienti.Tedesco: - serialeUpdate = tOut.uscita.chserial; - serialeLetto = serialeLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); - progressivoLetto = progressivoLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); - break; + // case Clienti.Syscom: + // serialeUpdate = tOut.uscita.chserial; + // serialeLetto = serialeLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); - case Clienti.Syscom: - serialeUpdate = tOut.uscita.chserial; - serialeLetto = serialeLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); + // progressivoLetto = progressivoLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); + // break; + // case Clienti.Maras: + // serialeUpdate = tOut.uscita.chserial; + // serialeLetto = serialeLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, serialeLetto, tablecodeSer, warncodeSer); - progressivoLetto = progressivoLetto + 1; - tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); - break; - } + // progressivoLetto = progressivoLetto + 1; + // tOut.prog_Out = await aggiornaprogressivoDecimal(ten, progressivoLetto, tablecodeProg, warncodeProg); + // break; + //} i.codice_impianto = tOut.uscita.chcodimp; i.seriale_chiamata = tOut.uscita.chserial; @@ -12053,7 +11737,6 @@ namespace ApiPolo.Controllers tOut.uscita.err_status_code = StatiRisposta.ErroreInterno; return StatusCode(StatusCodes.Status500InternalServerError, tOut.uscita); } - //return tOut; } private Output_Ricerca fillOutputRicerca(Commessa i) { @@ -12412,14 +12095,15 @@ namespace ApiPolo.Controllers { ten = ten2; } - //_chiatable = getChiamateTableByTenant(ten); - //_chiatableTaskManager = getChiamateTableTaskManagerByTenant(ten); - + _chiatable = getChiamateTableByTenant(ten); _confLette = await readConf(tenConf); serialeTemplate = _confLette.seriale_template_chi; tt = await _chiatable.Where(t => t.chcodazi != null && t.chcodazi.Equals(ten) && t.chserial != null && t.chserial.Equals(serialeTemplate)).ToListAsync(); + t = fillChiamateTableInput(tt.FirstOrDefault(), codimp, tecnico, ten, serLetto, progLetto, codice_commessa); + _service.AddChiamateTableToDbAsync(ten, t); + System.Threading.Thread.Sleep(1000); //scrittura /* @@ -12515,20 +12199,23 @@ namespace ApiPolo.Controllers break; } */ - _chiamate = getChiamateByTenant(ten); - switch (ten) - { - case Clienti.LW: - case Clienti.Syscom: - var chiamata_newTM = _chiamate.Where(x => x.chserial.Equals(tm.chserial)).FirstOrDefault(); - c = fillChiamateOut(chiamata_newTM, ten); - break; - default: - var chiamata_new = _chiamate.Where(x => x.chserial.Equals(t.chserial)).FirstOrDefault(); - c = fillChiamateOut(chiamata_new, ten); - break; - } + _chiamate = getChiamateByTenant(ten); + var chiamata_newTM = _chiamate.Where(x => x.chserial.Equals(t.chserial)).FirstOrDefault(); + c = fillChiamateOut(chiamata_newTM, ten); + + //switch (ten) + //{ + // case Clienti.LW: + // case Clienti.Syscom: + + // break; + + // default: + // var chiamata_new = _chiamate.Where(x => x.chserial.Equals(t.chserial)).FirstOrDefault(); + // c = fillChiamateOut(chiamata_new, ten); + // break; + //} return c; @@ -12551,94 +12238,9 @@ namespace ApiPolo.Controllers string newSerial = string.Empty; newSerial = await getSeriale(token); Rapp_New r = await fillRappNewByInput(model, token, newSerial, _confLette); - //scrittura - /* - switch (ten) - { - case Clienti.Marrocco: - using (var transaction = _Marro_rapp.Database.BeginTransaction()) - { - await _Marro_rapp.Rapps.AddAsync(r); - await _Marro_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Ferrari: - using (var transaction = _Ferra_rapp.Database.BeginTransaction()) - { - await _Ferra_rapp.Rapps.AddAsync(r); - await _Ferra_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Sicilia: - using (var transaction = _Sicilia_rapp.Database.BeginTransaction()) - { - await _Sicilia_rapp.Rapps.AddAsync(r); - await _Sicilia_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Discovery: - using (var transaction = _Disco_rapp.Database.BeginTransaction()) - { - await _Disco_rapp.Rapps.AddAsync(r); - await _Disco_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Sarom: - using (var transaction = _Sarom_rapp.Database.BeginTransaction()) - { - await _Sarom_rapp.Rapps.AddAsync(r); - await _Sarom_rapp.SaveChangesAsync(); - transaction.Commit(); - } - break; - case Clienti.Gitoga: - using (var transactionGit = _Gitoga_rapp.Database.BeginTransaction()) - { - await _Gitoga_rapp.Rapps.AddAsync(r); - await _Gitoga_rapp.SaveChangesAsync(); - transactionGit.Commit(); - } - break; - case Clienti.Lifta: - using (var transactionLif = _Lifta_rapp.Database.BeginTransaction()) - { - await _Lifta_rapp.Rapps.AddAsync(r); - await _Lifta_rapp.SaveChangesAsync(); - transactionLif.Commit(); - } - break; - case Clienti.Siet: - using (var transactionSiet = _Siet_rapp.Database.BeginTransaction()) - { - await _Siet_rapp.Rapps.AddAsync(r); - await _Siet_rapp.SaveChangesAsync(); - transactionSiet.Commit(); - } - break; - case Clienti.PMS: - using (var transactionPMS = _Pms_rapp.Database.BeginTransaction()) - { - await _Pms_rapp.Rapps.AddAsync(r); - await _Pms_rapp.SaveChangesAsync(); - transactionPMS.Commit(); - } - break; - case Clienti.VT: - using (var transactionvt = _VT_rapptable.Database.BeginTransaction()) - { - await _VT_rapptable.Rapps.AddAsync(r); - await _VT_rapptable.SaveChangesAsync(); - transactionvt.Commit(); - } - break; - default: - break; - } - */ + _service.AddRappNewToDbAsync(ten, r); + System.Threading.Thread.Sleep(1000); + //restituisco la chiamata calltec = await getChiamataBySerial(model.seriale_chiamata, token); calltec_out = fillChiamateOut(calltec, ten); @@ -12784,6 +12386,13 @@ namespace ApiPolo.Controllers Prog_out cso = new Prog_out(); string cpcccchk = getCpccchk(10); + _cpwarns = getCpwarnByTenant(tenant); + Prog2 entitasViewModel = _cpwarns.Where(p => p.tablecode.Equals(tablecode) && p.warncode.Equals(warncode)).FirstOrDefault(); + entitasViewModel.autonum = nuovoProg; + entitasViewModel.cpccchk = cpcccchk; + _service.UpdCpwarnToDbAsync(tenant, entitasViewModel); + System.Threading.Thread.Sleep(1000); + //scrittura /* switch (tenant) diff --git a/ApiPolo/Data/Maras_DbContext.cs b/ApiPolo/Data/Maras_DbContext.cs index 3fc45a4..460f946 100644 --- a/ApiPolo/Data/Maras_DbContext.cs +++ b/ApiPolo/Data/Maras_DbContext.cs @@ -59,6 +59,7 @@ namespace ApiPolo.Data public DbSet? Prog { get; set; } //public DbSet? Progressivi { get; set; } //public DbSet? Compo { get; set; } + public DbSet? ChiamateTables { get; set; } #endregion diff --git a/ApiPolo/Data/TenantDbContext.cs b/ApiPolo/Data/TenantDbContext.cs index e788f4b..44c6118 100644 --- a/ApiPolo/Data/TenantDbContext.cs +++ b/ApiPolo/Data/TenantDbContext.cs @@ -61,6 +61,8 @@ namespace ApiPolo.Data public DbSet? Prog { get; set; } //public DbSet? Progressivi { get; set; } //public DbSet? Compo { get; set; } + + public DbSet? ChiamateTables { get; set; } #endregion public TenantDbContext(DbContextOptions options, IConfiguration configuration, string tenant) @@ -196,6 +198,16 @@ namespace ApiPolo.Data table.warncode }); }, "CPWARN"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("CHIAMATE"); + mb.Entity().HasKey(table => new + { + table.chcodazi, + table.chserial + }); + }, "CHIAMATE"); } } } diff --git a/ApiPolo/Interfaces/ITenantDbContext.cs b/ApiPolo/Interfaces/ITenantDbContext.cs index 41cabc1..3cdef08 100644 --- a/ApiPolo/Interfaces/ITenantDbContext.cs +++ b/ApiPolo/Interfaces/ITenantDbContext.cs @@ -33,7 +33,7 @@ namespace ApiPolo.Interfaces DbSet? Prog { get; set; } //DbSet? Progressivi { get; set; } //DbSet? Compo { get; set; } - + public DbSet? ChiamateTables { get; set; } } diff --git a/ApiPolo/Service.cs b/ApiPolo/Service.cs index 3d92c1d..4bfcde5 100644 --- a/ApiPolo/Service.cs +++ b/ApiPolo/Service.cs @@ -48,7 +48,7 @@ namespace ApiPolo // } //} - /// + /// Scrive su Rapp_new: prendi in carico, rifiuta, chiudi public async Task AddRappNewToDbAsync(string tenant, Rapp_New model) { @@ -71,7 +71,7 @@ namespace ApiPolo } } - /// + /// Cancella da Rapp_new: rilascia public async Task RemoveRappNewToDbAsync(string tenant, Rapp_New model) { var dbContext = _dbContextFactory.GetDbContext(tenant); @@ -93,5 +93,64 @@ namespace ApiPolo } } + /// Scrive su Chiamate: inserimento chiamata da APP + public async Task AddChiamateTableToDbAsync(string tenant, ChiamateTable model) + { + + var dbContext = _dbContextFactory.GetDbContext(tenant); + + string mex = string.Empty; + try + { + using (var transaction = await dbContext.Database.BeginTransactionAsync()) + { + await dbContext.ChiamateTables.AddAsync(model); + await dbContext.SaveChangesAsync(); + await transaction.CommitAsync(); + } + } + catch (Exception ex) + { + mex = ex.Message; + throw new InvalidOperationException("Error in Service - AddRappNewToDbAsync: " + mex); + } + } + + /// Aggiorna Cpwarn: aggiornamento serieli e progressini + public async Task UpdCpwarnToDbAsync(string tenant, Prog2 model) + { + + var dbContext = _dbContextFactory.GetDbContext(tenant); + + + string mex = string.Empty; + try + { + using (var transaction = await dbContext.Database.BeginTransactionAsync()) + { + dbContext.Entry(model).State = EntityState.Modified; + await dbContext.SaveChangesAsync(); + await transaction.CommitAsync(); + } + + //using (var transactionLW = _LW_cpwarn.Database.BeginTransaction()) + //{ + // _cpwarns = getCpwarnByTenant(tenant); + // Prog2 entitasViewModel = _cpwarns.Where(p => p.tablecode.Equals(tablecode) && p.warncode.Equals(warncode)).FirstOrDefault(); + // entitasViewModel.autonum = nuovoProg; + // entitasViewModel.cpccchk = cpcccchk; + + // _LW_cpwarn.Entry(entitasViewModel).State = EntityState.Modified; + // await _LW_cpwarn.SaveChangesAsync(); + // transactionLW.Commit(); + //} + } + catch (Exception ex) + { + mex = ex.Message; + throw new InvalidOperationException("Error in Service - AddRappNewToDbAsync: " + mex); + } + } + } }