diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index a484ff3..e8230b7 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -1,46 +1,44 @@ using ApiPolo.Models; - - -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; -using Renci.SshNet; -using System.IdentityModel.Tokens.Jwt; -using System.Net; -using System.Security.Claims; -using System.Text; - -using System.Collections.Generic; -using System.Drawing; +using ApiPolo.Models.VT_dbcontext; using FirebaseAdmin; +using FirebaseAdmin.Auth.Multitenancy; using FirebaseAdmin.Messaging; using Google.Apis.Auth.OAuth2; -using Newtonsoft.Json; -using static ApiPolo.Controllers.PoloController; -using System.Net.Http.Headers; -using Newtonsoft.Json.Linq; -using System.Linq.Expressions; -using FirebaseAdmin.Auth.Multitenancy; -using System.Globalization; -using ApiPolo.Models.VT_dbcontext; -using System.Diagnostics.Contracts; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Storage; -using System.Diagnostics.Metrics; -using System.Transactions; -using System.Web.Razor.Parser; +using Microsoft.Extensions.Primitives; +using Microsoft.IdentityModel.Tokens; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Renci.SshNet; using System; using System.Collections; -using Microsoft.EntityFrameworkCore.Metadata.Internal; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Diagnostics.Contracts; +using System.Diagnostics.Metrics; +using System.Drawing; +using System.Globalization; +using System.IdentityModel.Tokens.Jwt; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Net; +using System.Net.Http.Headers; +using System.Runtime.CompilerServices; +using System.Security.Claims; +using System.Text; +using System.Text.RegularExpressions; +using System.Transactions; +using System.Web.Razor.Parser; +using static ApiPolo.Controllers.PoloController; using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; using static System.Net.Mime.MediaTypeNames; -using System.IO; -using Microsoft.AspNetCore.Http; -using System.Data; -using System.Linq; -using Microsoft.Extensions.Primitives; -using System.Text.RegularExpressions; -using System.Runtime.CompilerServices; -using System.Diagnostics; namespace ApiPolo.Controllers { @@ -136,6 +134,7 @@ namespace ApiPolo.Controllers #region VT-TIMBRATURE private readonly VT_TIMBRATURE_DbContext _VT_timbr; + private readonly VT_TIMBRATURE_VW_DbContext _VT_VW_timbr; #endregion #region VT-ARTICOLI @@ -172,6 +171,7 @@ namespace ApiPolo.Controllers private DbSet? _pagam; private DbSet? _comm; private DbSet? _timbr; + private DbSet? _timbrVW; private DbSet? _sto_imp; private DbSet? _azi_coll; private DbSet? _impianto; @@ -238,6 +238,7 @@ namespace ApiPolo.Controllers VT_Buoni_DbContext VT_Buoni, VT_STO_RAPP_DbContext VT_StoRapp, VT_TIMBRATURE_DbContext VT_timbr, + VT_TIMBRATURE_VW_DbContext VT_VW_timbr, VT_ARTICOLI_TABLE_DbContext VT_artTable, VT_MAG_NEW_DbContext VT_MagNew, VT_MAGAZZINI_DbContext VT_Magazzini, @@ -280,6 +281,7 @@ namespace ApiPolo.Controllers _VT_Buoni = VT_Buoni; _VT_StoRapp = VT_StoRapp; _VT_timbr = VT_timbr; + _VT_VW_timbr = VT_VW_timbr; _VT_articoliTable = VT_artTable; _VT_MagNew = VT_MagNew; _VT_Magazzini = VT_Magazzini; @@ -529,17 +531,29 @@ namespace ApiPolo.Controllers } return seriale; } - private static readonly SemaphoreSlim _serialLock = new(1, 1); - private async Task GetSerialeThreadSafe(string token) + private static readonly ConcurrentDictionary _locks = new(); + private static SemaphoreSlim GetLockForTenant(string tenant) { - await _serialLock.WaitAsync(); + return _locks.GetOrAdd(tenant, _ => new SemaphoreSlim(1, 1)); + } + + [NonAction] + /// gestione della concorrenza + public async Task GetSerialeThreadSafe(string token) + { + string ten = getClaimValueByToken(token, "tenant") ?? + getClaimValueByToken(token, "tenantConfigurazioni"); + + var sem = GetLockForTenant(ten); + + await sem.WaitAsync(); try { return await getSerialeInternal(token); } finally { - _serialLock.Release(); + sem.Release(); } } @@ -4204,21 +4218,6 @@ namespace ApiPolo.Controllers return o; } - private async Task getDescrImpTedesco(string codimp, string ten) - { - string descImp = string.Empty; - //_impianto = _Tedes_impianti.Impia; - var l = await _impianto.Where(t => t.imcodazi != null && t.imcodazi.Equals(ten) && t.imcodimp != null && t.imcodimp.Equals(codimp)).ToListAsync(); - if (l != null && l.Count()>0 ) - { - foreach(Impianto i in l) - { - descImp = i.imdescri; - } - } - return descImp; - } - /// Manutenzioni per tecnico e azienda (tenant). Intervallo: 1 mese prima e 1 mese dopo rispetto a GETDATE() con GENERATO diverso da S return:ActionResult [HttpGet("manutenzioni")] public async Task>> manutenzioni(string token) @@ -4345,335 +4344,6 @@ namespace ApiPolo.Controllers newSerial = await getSeriale(token); Rapp_New r = await fillRappNewChiudiManByInput(model, token, newSerial, _confLette); - //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.Sarom: - // using (var transaction = _Sarom_rapp.Database.BeginTransaction()) - // { - // await _Sarom_rapp.Rapps.AddAsync(r); - // await _Sarom_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(); - // } - // int riga = 0; - // if (model.compo_add != null && model.compo_add.Count() > 0) - // { - - // using (var transaction2 = _Sicilia_mag.Database.BeginTransaction()) - // { - - // foreach (Saldiart co in model.compo_add) - // { - // riga = riga + 1; - // Mag_New mn = new Mag_New(); - // mn = saldiartToMag_New(co, riga, newSerial, tecnico); - - // await _Sicilia_mag.Mag.AddAsync(mn); - // await _Sicilia_mag.SaveChangesAsync(); - - // } - // transaction2.Commit(); - // } - // } - // if (model.compo_del != null && model.compo_del.Count() > 0) - // { - - - // using (var transaction3 = _Sicilia_mag.Database.BeginTransaction()) - // { - // foreach (Compo_Impia co in model.compo_del) - // { - // Mag_New mn = new Mag_New(); - // riga = riga + 1; - // mn = compo_ImpiaToMag_New(co, riga, newSerial, tecnico); - - // await _Sicilia_mag.Mag.AddAsync(mn); - // await _Sicilia_mag.SaveChangesAsync(); - // } - // transaction3.Commit(); - // } - // } - // break; - // case Clienti.Discovery: - // using (var transaction4 = _Disco_rapp.Database.BeginTransaction()) - // { - // await _Disco_rapp.Rapps.AddAsync(r); - // await _Disco_rapp.SaveChangesAsync(); - // transaction4.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(); - // } - // int rigaSiet = 0; - // if (model.compo_add != null && model.compo_add.Count() > 0) - // { - - // using (var transaction2 = _Siet_mag.Database.BeginTransaction()) - // { - - // foreach (Saldiart co in model.compo_add) - // { - // rigaSiet = rigaSiet + 1; - // Mag_New mn = new Mag_New(); - // mn = saldiartToMag_New(co, rigaSiet, newSerial, tecnico); - - // await _Siet_mag.Mag.AddAsync(mn); - // await _Siet_mag.SaveChangesAsync(); - - // } - // transaction2.Commit(); - // } - // } - // if (model.compo_del != null && model.compo_del.Count() > 0) - // { - // using (var transaction3 = _Siet_mag.Database.BeginTransaction()) - // { - // foreach (Compo_Impia co in model.compo_del) - // { - // Mag_New mn = new Mag_New(); - // rigaSiet = rigaSiet + 1; - // mn = compo_ImpiaToMag_New(co, rigaSiet, newSerial, tecnico); - - // await _Siet_mag.Mag.AddAsync(mn); - // await _Siet_mag.SaveChangesAsync(); - // } - // transaction3.Commit(); - // } - // } - - // break; - //case Clienti.PMS: - // using (var transactionPms = _Pms_rapp.Database.BeginTransaction()) - // { - // await _Pms_rapp.Rapps.AddAsync(r); - // await _Pms_rapp.SaveChangesAsync(); - // transactionPms.Commit(); - // } - // int rigapms = 0; - // if (model.compo_add != null && model.compo_add.Count() > 0) - // { - - // using (var transaction2 = _PMS_mag.Database.BeginTransaction()) - // { - - // foreach (Saldiart co in model.compo_add) - // { - // rigapms = rigapms + 1; - // Mag_New mn = new Mag_New(); - // mn = saldiartToMag_New(co, rigapms, newSerial, tecnico); - - // await _PMS_mag.Mag.AddAsync(mn); - // await _PMS_mag.SaveChangesAsync(); - - // } - // transaction2.Commit(); - // } - // } - // if (model.compo_del != null && model.compo_del.Count() > 0) - // { - // using (var transaction3 = _PMS_mag.Database.BeginTransaction()) - // { - // foreach (Compo_Impia co in model.compo_del) - // { - // Mag_New mn = new Mag_New(); - // rigapms = rigapms + 1; - // mn = compo_ImpiaToMag_New(co, rigapms, newSerial, tecnico); - - // await _PMS_mag.Mag.AddAsync(mn); - // await _PMS_mag.SaveChangesAsync(); - // } - // transaction3.Commit(); - // } - // } - - // break; - - //case Clienti.LW: - // using (var transactionLW = _LW_rapp.Database.BeginTransaction()) - // { - // await _LW_rapp.Rapps.AddAsync(r); - // await _LW_rapp.SaveChangesAsync(); - // transactionLW.Commit(); - // } - // int rigalw = 0; - // if (model.compo_add != null && model.compo_add.Count() > 0) - // { - - // using (var transaction2 = _LW_mag.Database.BeginTransaction()) - // { - - // foreach (Saldiart co in model.compo_add) - // { - // rigalw = rigalw + 1; - // Mag_New mn = new Mag_New(); - // mn = saldiartToMag_New(co, rigalw, newSerial, tecnico); - - // await _LW_mag.Mag.AddAsync(mn); - // await _LW_mag.SaveChangesAsync(); - - // } - // transaction2.Commit(); - // } - // } - // if (model.compo_del != null && model.compo_del.Count() > 0) - // { - // using (var transaction3 = _LW_mag.Database.BeginTransaction()) - // { - // foreach (Compo_Impia co in model.compo_del) - // { - // Mag_New mn = new Mag_New(); - // rigalw = rigalw + 1; - // mn = compo_ImpiaToMag_New(co, rigalw, newSerial, tecnico); - - // await _LW_mag.Mag.AddAsync(mn); - // await _LW_mag.SaveChangesAsync(); - // } - // transaction3.Commit(); - // } - // } - - // break; - - //case Clienti.Tedesco: - // using (var transactionTedes = _Tedes_rapp.Database.BeginTransaction()) - // { - // await _Tedes_rapp.Rapps.AddAsync(r); - // await _Tedes_rapp.SaveChangesAsync(); - // transactionTedes.Commit(); - // } - // int rigatedes = 0; - // if (model.compo_add != null && model.compo_add.Count() > 0) - // { - - // using (var transaction2 = _Tedes_mag.Database.BeginTransaction()) - // { - - // foreach (Saldiart co in model.compo_add) - // { - // rigatedes = rigatedes + 1; - // Mag_New mn = new Mag_New(); - // mn = saldiartToMag_New(co, rigatedes, newSerial, tecnico); - - // await _Tedes_mag.Mag.AddAsync(mn); - // await _Tedes_mag.SaveChangesAsync(); - - // } - // transaction2.Commit(); - // } - // } - // if (model.compo_del != null && model.compo_del.Count() > 0) - // { - // using (var transaction3 = _Tedes_mag.Database.BeginTransaction()) - // { - // foreach (Compo_Impia co in model.compo_del) - // { - // Mag_New mn = new Mag_New(); - // rigatedes = rigatedes + 1; - // mn = compo_ImpiaToMag_New(co, rigatedes, newSerial, tecnico); - - // await _Tedes_mag.Mag.AddAsync(mn); - // await _Tedes_mag.SaveChangesAsync(); - // } - // transaction3.Commit(); - // } - // } - - // break; - - //case Clienti.Syscom: - // using (var transactionSys = _Sys_rapp.Database.BeginTransaction()) - // { - // await _Sys_rapp.Rapps.AddAsync(r); - // await _Sys_rapp.SaveChangesAsync(); - // transactionSys.Commit(); - // } - // int rigasys = 0; - // if (model.compo_add != null && model.compo_add.Count() > 0) - // { - - // using (var transaction2 = _Sys_mag.Database.BeginTransaction()) - // { - - // foreach (Saldiart co in model.compo_add) - // { - // rigasys = rigasys + 1; - // Mag_New mn = new Mag_New(); - // mn = saldiartToMag_New(co, rigasys, newSerial, tecnico); - - // await _Sys_mag.Mag.AddAsync(mn); - // await _Sys_mag.SaveChangesAsync(); - - // } - // transaction2.Commit(); - // } - // } - // if (model.compo_del != null && model.compo_del.Count() > 0) - // { - // using (var transaction3 = _Sys_mag.Database.BeginTransaction()) - // { - // foreach (Compo_Impia co in model.compo_del) - // { - // Mag_New mn = new Mag_New(); - // rigasys = rigasys + 1; - // mn = compo_ImpiaToMag_New(co, rigasys, newSerial, tecnico); - - // await _Sys_mag.Mag.AddAsync(mn); - // await _Sys_mag.SaveChangesAsync(); - // } - // transaction3.Commit(); - // } - // } - - // break; - //default: - // break; - //} man = await getManutenzioneByChiaveOut(model, token,r); output = fillManprogOut(man, ten); output.err_status_code = StatiRisposta.Ok; @@ -12732,6 +12402,35 @@ namespace ApiPolo.Controllers } } + /// VIRTUAL TASK: Timbrature da App + [HttpGet("timbratureListVW")] + public async Task>> timbratureListVW(string token) + { + try + { + List ilist = new List(); + string ten = getClaimValueByToken(token, "tenant2"); + string tecnico = getClaimValueByToken(token, "tccodice"); + _timbrVW = _VT_VW_timbr.Timbs; + + + var t = await _timbrVW.Where( + t => t.azienda.Equals(ten) + ).ToListAsync(); + + foreach (TimbraturaView ch in t) + { + ilist.Add(ch); + } + return StatusCode(StatusCodes.Status200OK, ilist); + } + catch (Exception ex) + { + string err = "Errore: " + ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, err); + } + } + /// VIRTUAL TASK: lista articoli per azienda [HttpGet("articoliList")] public async Task>> ArticoliList(string token) diff --git a/ApiPolo/Models/TimbraturaView.cs b/ApiPolo/Models/TimbraturaView.cs new file mode 100644 index 0000000..fac0961 --- /dev/null +++ b/ApiPolo/Models/TimbraturaView.cs @@ -0,0 +1,61 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiPolo.Models +{ + /// Vista API_TIMBRATURE_VT + [Keyless] + public class TimbraturaView + { + public int id { get; set; } + + /// data + public DateTime? data_timbratura { get; set; } + + /// ora inizio + public int ora_ini { get; set; } + + /// minuto inizio + public int min_ini { get; set; } + + /// ora fine + public int ora_fin { get; set; } + + /// minuto fine + public int min_fin { get; set; } + + /// SERIALE commessa + public string? commessa { get; set; } + + /// ore viaggio + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(7, 2)")] + public decimal? ore_viaggio { get; set; } + + /// totale ore + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(7, 2)")] + public decimal? tot_ore { get; set; } + + /// giorno settimana + public int? giorno { get; set; } + + /// azienda + public string? azienda { get; set; } + + /// tecnico + public string? tecnico { get; set; } + + /// cpccchk + public string? cpccchk { get; set; } + + /// note + public string? note { get; set; } + + /// Giorno della settimana descrizione + public string? giodesc { get; set; } + + /// Commessa descrizione + public string? commdesc { get; set; } + + /// tecnico descrizione + public string? tecdesc { get; set; } + } +} diff --git a/ApiPolo/Models/VT_dbcontext/VT_TIMBRATURE_VW_DbContext.cs b/ApiPolo/Models/VT_dbcontext/VT_TIMBRATURE_VW_DbContext.cs new file mode 100644 index 0000000..2a303c9 --- /dev/null +++ b/ApiPolo/Models/VT_dbcontext/VT_TIMBRATURE_VW_DbContext.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiPolo.Models.VT_dbcontext +{ + /// + public class VT_TIMBRATURE_VW_DbContext: DbContext + { + /// + public DbSet? Timbs { get; set; } + + /// + public VT_TIMBRATURE_VW_DbContext(DbContextOptions options) : base(options) + { + } + + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToView("API_TIMBRATURE_VT"); + } + } +} diff --git a/ApiPolo/Startup.cs b/ApiPolo/Startup.cs index ce89de9..9c0613a 100644 --- a/ApiPolo/Startup.cs +++ b/ApiPolo/Startup.cs @@ -103,6 +103,9 @@ namespace ApiPolo services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("VIRTUAL_TASK") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); diff --git a/ApiPolo/appsettings.json b/ApiPolo/appsettings.json index 5be9820..1af19a4 100644 --- a/ApiPolo/appsettings.json +++ b/ApiPolo/appsettings.json @@ -14,8 +14,8 @@ "ApiStr": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=API_POLO;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True", //"ApiStr": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True", - "VIRTUAL_TASK": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=VIRTUAL_TASK;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True" - //"VIRTUAL_TASK": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=VIRTUAL_TASK;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + //"VIRTUAL_TASK": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=VIRTUAL_TASK;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True" + "VIRTUAL_TASK": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=VIRTUAL_TASK;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", //"VIRTUAL_TASK": "Data Source=172.25.30.1;Initial Catalog=VIRTUAL_TASK;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" }, diff --git a/ApiPolo/wwwroot/VIRTU/AZI02/servizi_associati_perugia_logo.jpg b/ApiPolo/wwwroot/VIRTU/AZI02/servizi_associati_perugia_logo.jpg new file mode 100644 index 0000000..d044c6c Binary files /dev/null and b/ApiPolo/wwwroot/VIRTU/AZI02/servizi_associati_perugia_logo.jpg differ diff --git a/ApiPolo/wwwroot/VIRTU/AZI02/sulga.png b/ApiPolo/wwwroot/VIRTU/AZI02/sulga.png new file mode 100644 index 0000000..8f78a73 Binary files /dev/null and b/ApiPolo/wwwroot/VIRTU/AZI02/sulga.png differ