From ebe47444bfae7d18f2b8b7769e21f89d08f8f1bd Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Thu, 25 Jul 2024 18:13:07 +0200 Subject: [PATCH] Testata movib_m --- Controllers/GiriController.cs | 44 +++++++++++++++---- Models/Consegna.cs | 2 +- Models/Consegna_m.cs | 26 +++++++++++ Models/Consegna_out.cs | 2 +- .../Gesa_DbContext/GESA_CONSEGNE_DbContext.cs | 2 +- .../GESA_CONSEGNE_M_DbContext.cs | 25 +++++++++++ Models/GiriConsegnaView.cs | 1 + Program.cs | 7 ++- appsettings.json | 1 + 9 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 Models/Consegna_m.cs create mode 100644 Models/Gesa_DbContext/GESA_CONSEGNE_M_DbContext.cs diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs index d4c3ee4..45d148e 100644 --- a/Controllers/GiriController.cs +++ b/Controllers/GiriController.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; +using System; using System.Diagnostics; using System.IdentityModel.Tokens.Jwt; using System.Runtime.InteropServices; @@ -29,6 +30,7 @@ namespace ApiSoftway.Controllers private readonly GESA_AUTOMEZZI_DbContext _automezzi_context; private readonly IConfiguration? _configuration; private readonly GESA_GIRICONSEGNEDACREARE_DbContext _daCreare_context; + private readonly GESA_CONSEGNE_M_DbContext _consegne_m_context; private DbSet? _giri; private DbSet? _giriCons; @@ -41,7 +43,8 @@ namespace ApiSoftway.Controllers private DbSet? _GiriDaCreare; public GiriController(ILogger logger, IConfiguration? configuration, GESA_GIRI_DbContext giri_context, GESA_DESTINAZIONI_DbContext destinazioni_context , GESA_CONSEGNE_DbContext consegne_context, GESA_GIRICONSEGNE_DbContext giricons_context, GESA_GIRICONSEGNEVISTA_DbContext consegnevista_context, GESA_SBR_ORD_DbContext sbrord_context - , GESA_PERSONALE_DbContext personale_context, GESA_AUTOMEZZI_DbContext automezzi_context, GESA_GIRICONSEGNEDACREARE_DbContext daCreare_context) + , GESA_PERSONALE_DbContext personale_context, GESA_AUTOMEZZI_DbContext automezzi_context, GESA_GIRICONSEGNEDACREARE_DbContext daCreare_context + , GESA_CONSEGNE_M_DbContext consegne_m_context) { _logger = logger; _configuration = configuration; @@ -54,6 +57,7 @@ namespace ApiSoftway.Controllers _personale_context= personale_context; _automezzi_context = automezzi_context; _daCreare_context = daCreare_context; + _consegne_m_context = consegne_m_context; } [HttpGet("listaGiri")] @@ -668,7 +672,22 @@ namespace ApiSoftway.Controllers //string tecnico = getClaimValueByToken(token, "tccodice"); if (await checkConsegnaPresente(token, model) == 0) { - Consegna t = fillConsegna(model, token); + + DateTime dateTime = DateTime.Now; + Consegna t = fillConsegna(model, token, dateTime); + //Step 1 : testata + Consegna_m m = new Consegna_m(); + m.Pisergir = t.Pisergir; + m.Data = dateTime; + m.Cpccchk = getCpccchk(10); + using (var transactionM = _consegne_m_context.Database.BeginTransaction()) + { + await _consegne_m_context.Cons.AddAsync(m); + await _consegne_m_context.SaveChangesAsync(); + transactionM.Commit(); + } + + //step 2 : riga (è sempre e solo una) using (var transaction = _consegne_context.Database.BeginTransaction()) { await _consegne_context.Cons.AddAsync(t); @@ -739,11 +758,12 @@ namespace ApiSoftway.Controllers } } + private async Task checkConsegnaPresente(string token, Consegna model) { int trovati = 0; _consegne = _consegne_context.Cons; - var ti = await _consegne.Where(t => t.Serial.Equals(model.Serial) && t.Cprownum == model.Cprownum ).ToListAsync(); + var ti = await _consegne.Where(t => t.Pisergir.Equals(model.Pisergir) && t.Cprownum == model.Cprownum ).ToListAsync(); if (ti.Any()) { trovati = ti.Count(); @@ -841,7 +861,7 @@ namespace ApiSoftway.Controllers return item; } - private Consegna fillConsegna(Consegna i, string token) + private Consegna fillConsegna(Consegna i, string token, DateTime d) { Consegna r = new Consegna(); @@ -858,7 +878,7 @@ namespace ApiSoftway.Controllers r.Ccadd = i.Ccadd; r.Ccda = i.Ccda; r.Ccddd=i.Ccddd; - r.Datdoc= DateTime.Now; + r.Datdoc= d; r.Dcda=i.Dcda; r.Descb=i.Descb; r.Nbanc = i.Nbanc; @@ -870,7 +890,7 @@ namespace ApiSoftway.Controllers r.Tipob2 = i.Tipob2; r.Tipob =i.Tipob; r.Sdoc = i.Sdoc; - r.Serial = i.Serial; + r.Pisergir = i.Pisergir; //r.Tcda=i.Tcda; r.Tcda = "S"; r.Tca = i.Tca; @@ -912,7 +932,7 @@ namespace ApiSoftway.Controllers r.Tipob2 = i.Tipob2; r.Tipob = i.Tipob; r.Sdoc = i.Sdoc; - r.Serial = i.Serial; + r.Pisergir = i.Pisergir; //r.Tcda=i.Tcda; r.Tcda = "N"; r.Tca = i.Tca; @@ -955,7 +975,7 @@ namespace ApiSoftway.Controllers r.Tipob2 = i.Tipob2; r.Tipob = i.Tipob; r.Sdoc = i.Sdoc; - r.Serial = i.Serial; + r.Pisergir = i.Pisergir; r.Tcda = i.Tcda; r.Tca = i.Tca; r.Cca = i.Cca; @@ -983,6 +1003,14 @@ namespace ApiSoftway.Controllers return newSer; } + + private static Random random = new Random(); + /// crea un cpccchk + public static string getCpccchk(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); + } } } diff --git a/Models/Consegna.cs b/Models/Consegna.cs index 6b95a63..9078ba0 100644 --- a/Models/Consegna.cs +++ b/Models/Consegna.cs @@ -5,7 +5,7 @@ namespace ApiSoftway.Models public class Consegna { [Key] - public string? Serial { get; set; } + public string? Pisergir { get; set; } [Key] public int? Cprownum { get; set; } diff --git a/Models/Consegna_m.cs b/Models/Consegna_m.cs new file mode 100644 index 0000000..0e3e7bb --- /dev/null +++ b/Models/Consegna_m.cs @@ -0,0 +1,26 @@ +using System.ComponentModel.DataAnnotations; + +namespace ApiSoftway.Models +{ + public class Consegna_m + { + [Key] + public string? Pisergir { get; set; } + public string? Esercizio { get; set; } + public int? Numero { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(10, 0)")] + public int? Posseriale { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(10, 0)")] + public int? Posnum { get; set; } + + public string? Posese { get; set; } + + public DateTime? Data { get; set; } + + public string? Descmov { get; set; } + + public string? Cpccchk { get; set; } + } +} diff --git a/Models/Consegna_out.cs b/Models/Consegna_out.cs index f677d6b..a4bab62 100644 --- a/Models/Consegna_out.cs +++ b/Models/Consegna_out.cs @@ -4,7 +4,7 @@ namespace ApiSoftway.Models { public class Consegna_out { - public string? Serial { get; set; } + public string? Pisergir { get; set; } public int? Cprownum { get; set; } public string? Tcda { get; set; } public string? Ccda { get; set; } diff --git a/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs b/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs index 54106f1..b95fe67 100644 --- a/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs +++ b/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs @@ -17,7 +17,7 @@ namespace ApiSoftway.Models.Gesa_DbContext { modelBuilder.Entity().ToTable("GESASMOVIB"); modelBuilder.Entity().HasKey(table => new { - table.Serial, + table.Pisergir, table.Cprownum }); } diff --git a/Models/Gesa_DbContext/GESA_CONSEGNE_M_DbContext.cs b/Models/Gesa_DbContext/GESA_CONSEGNE_M_DbContext.cs new file mode 100644 index 0000000..741f513 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_CONSEGNE_M_DbContext.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_CONSEGNE_M_DbContext : DbContext + { + /// + public DbSet? Cons { get; set; } + + /// + public GESA_CONSEGNE_M_DbContext(DbContextOptions options) : base(options) + { + } + + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("GESASMOVIB_m"); + modelBuilder.Entity().HasKey(table => new { + table.Pisergir + + }); + } + } +} diff --git a/Models/GiriConsegnaView.cs b/Models/GiriConsegnaView.cs index f339200..a73d6b9 100644 --- a/Models/GiriConsegnaView.cs +++ b/Models/GiriConsegnaView.cs @@ -33,6 +33,7 @@ namespace ApiSoftway.Models public int? DestinazioniFatte { get; set; } public int? DestinazioniTutte { get; set; } public int? DestinazioniModificate { get; set; } + public int? parzialeBanSca { get; set; } } } diff --git a/Program.cs b/Program.cs index 57ce991..7688b2a 100644 --- a/Program.cs +++ b/Program.cs @@ -48,6 +48,9 @@ builder.Services.AddDbContext(options => options.UseSqlSe builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") , options => { options.CommandTimeout(commandTimeoutInSeconds); } )); +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); #endregion @@ -71,5 +74,5 @@ app.UseAuthorization(); app.MapControllers(); -app.Run(); -//app.Run("http://localhost:6000"); +//app.Run(); +app.Run("http://localhost:6000"); diff --git a/appsettings.json b/appsettings.json index 31f88b6..618af2e 100644 --- a/appsettings.json +++ b/appsettings.json @@ -9,6 +9,7 @@ "ConnectionStrings": { "GESA": "Data Source=10.0.0.10;Initial Catalog=AHRGESA;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + //"GESA": "Data Source=10.0.0.10;Initial Catalog=AHR80_GESA;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", "ApiStr": "Data Source=10.0.0.10;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" }, "JWT": {