diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs index 22c1975..8e46c42 100644 --- a/Controllers/GiriController.cs +++ b/Controllers/GiriController.cs @@ -170,6 +170,7 @@ namespace ApiSoftway.Controllers gc.Pidata = model.DataGiro; gc.Pisergir = newSer; gc.Pidarecu = model.ImportoDaRecuperare; + gc.Pimezzo = model.CodMezzo; using (var transactionGiri = _giricons_context.Database.BeginTransaction()) { await _giricons_context.GiriCons.AddAsync(gc); @@ -428,7 +429,7 @@ namespace ApiSoftway.Controllers List lst = new List(); _destinazioni = _destinazioni_context.Destinazioni; - var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(autista) && t.DataCarico != null && t.DataCarico == dataGiro && t.CodAutomezzo!=null && t.CodAutomezzo.Equals(mezzo)).OrderByDescending(t => t.DataCarico).ToListAsync(); + var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(autista) && t.DataCarico != null && t.DataCarico == dataGiro && t.CodAutomezzo!=null && t.CodAutomezzo.Equals(mezzo)).OrderByDescending(t => t.DataCarico).ThenBy(t=>t.Seq).ToListAsync(); foreach (Destinazioni d in r) { Destinazioni_out o = new Destinazioni_out(); @@ -472,6 +473,7 @@ namespace ApiSoftway.Controllers o.Uova=d.Uova; o.Cist=d.Cist; o.Note=d.Note; + o.Seq = d.Seq; if (!string.IsNullOrEmpty(d.consFattaSerial)) diff --git a/Controllers/ModificaGiroController.cs b/Controllers/ModificaGiroController.cs new file mode 100644 index 0000000..f6831ab --- /dev/null +++ b/Controllers/ModificaGiroController.cs @@ -0,0 +1,93 @@ +using ApiSoftway.Models; +using ApiSoftway.Models.Gesa_DbContext; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; + +namespace ApiSoftway.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ModificaGiroController : ControllerBase + { + private readonly ILogger _logger; + private readonly IConfiguration? _configuration; + private readonly GESA_MODGIR_DbContext _modgiri_context; + private DbSet? _modgir; + public ModificaGiroController(ILogger logger, IConfiguration? configuration, GESA_MODGIR_DbContext modgiri_context) + { + _logger = logger; + _configuration = configuration; + _modgiri_context= modgiri_context; + } + /// Salva i dati della consegna + [HttpPost] + [Route("addModgir")] + public async Task> addModgir(Modgir model) + { + Modgir_out tOut = new Modgir_out(); + //string usr = getClaimValueByToken(token, "codice"); + try + { + //step 1 : calcolo il nuovo seriale + _modgir = _modgiri_context.Mod; + var ser = await _modgir.Take(1).OrderByDescending(t => t.Piprogre).ToListAsync(); + string ultSer = string.Empty; + if (ser!=null && ser.Count()>0) + { + ultSer = ser.First().Piprogre; + } + + string newSer = calcolaNuovoSeriale(ultSer); + + //step 2 : inserisco in PIGIRCON + Modgir gc = new Modgir(); + + gc.Piprogre = newSer; + gc.Piserial = model.Piserial; + gc.Pidata = model.Pidata; + gc.Picommit = model.Picommit; + gc.Pidesdiv = model.Pidesdiv; + gc.Pitarga = model.Pitarga; + gc.Piautist = model.Piautist; + gc.Pitiprec = model.Pitiprec; + + using (var transactionGiri = _modgiri_context.Database.BeginTransaction()) + { + await _modgiri_context.Mod.AddAsync(gc); + await _modgiri_context.SaveChangesAsync(); + transactionGiri.Commit(); + } + + var giro = await _modgiri_context.Mod.Where(t => t.Piprogre.Equals(newSer)).ToListAsync(); + return StatusCode(StatusCodes.Status200OK, giro.First()); + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + tOut.err_title = ex.Message; + tOut.err_detail = errmsg; + tOut.err_status_code = "500"; + return StatusCode(StatusCodes.Status500InternalServerError, tOut); + } + } + private string calcolaNuovoSeriale(string ultSer) + { + string newSer = "0000000000"; + + if(!string.IsNullOrEmpty(ultSer)) + { + int ser = Convert.ToInt32(ultSer); + ser++; + newSer = Convert.ToString(ser); + + if (ser > 0) + { + newSer = newSer.PadLeft(10, '0'); + } + } + return newSer; + } + } +} diff --git a/Models/Destinazioni.cs b/Models/Destinazioni.cs index 0cb44da..d4ebe62 100644 --- a/Models/Destinazioni.cs +++ b/Models/Destinazioni.cs @@ -50,6 +50,7 @@ namespace ApiSoftway.Models public int? Uova { get; set; } public int? Cist { get; set; } public string? Note { get; set; } + public int? Seq { get; set; } } } diff --git a/Models/Destinazioni_out.cs b/Models/Destinazioni_out.cs index 7f8657e..8e7b305 100644 --- a/Models/Destinazioni_out.cs +++ b/Models/Destinazioni_out.cs @@ -36,6 +36,7 @@ namespace ApiSoftway.Models public int? Uova { get; set; } public int? Cist { get; set; } public string? Note { get; set; } + public int? Seq { get; set; } } public class ConsegnaFatta { diff --git a/Models/Gesa_DbContext/GESA_MODGIR_DbContext.cs b/Models/Gesa_DbContext/GESA_MODGIR_DbContext.cs new file mode 100644 index 0000000..84eb38b --- /dev/null +++ b/Models/Gesa_DbContext/GESA_MODGIR_DbContext.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_MODGIR_DbContext : DbContext + { + public DbSet? Mod { get; set; } + + /// + public GESA_MODGIR_DbContext(DbContextOptions options) : base(options) + { + } + + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("GESAPIMODGIR"); + modelBuilder.Entity().HasKey(table => new { + table.Piprogre + }); + } + } +} diff --git a/Models/GiriConsegna.cs b/Models/GiriConsegna.cs index e8f0f98..fd6f28b 100644 --- a/Models/GiriConsegna.cs +++ b/Models/GiriConsegna.cs @@ -19,5 +19,7 @@ namespace ApiSoftway.Models public DateTime? Pidatchi { get; set; } + public string? Pimezzo { get; set; } + } } diff --git a/Models/GiriConsegnaDaCreare.cs b/Models/GiriConsegnaDaCreare.cs index fc30bba..fad89de 100644 --- a/Models/GiriConsegnaDaCreare.cs +++ b/Models/GiriConsegnaDaCreare.cs @@ -5,7 +5,7 @@ namespace ApiSoftway.Models [Keyless] public class GiriConsegnaDaCreare { - public string? CodAutomezzo { get; set; } + public string? CodMezzo { get; set; } public string? CodAutista { get; set; } public string? Autista { get; set; } public string? Automezzo { get; set; } diff --git a/Models/GiriConsegnaView.cs b/Models/GiriConsegnaView.cs index 01e3908..8462d81 100644 --- a/Models/GiriConsegnaView.cs +++ b/Models/GiriConsegnaView.cs @@ -22,5 +22,12 @@ namespace ApiSoftway.Models public string? CodMezzo { get; set; } public string? Automezzo { get; set; } + + public int? parzialeBanRec { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] + public decimal? parzialeImpRec { get; set; } + + public string? NoteChiusura { get; set; } } } diff --git a/Models/Modgir.cs b/Models/Modgir.cs new file mode 100644 index 0000000..4fa6e5b --- /dev/null +++ b/Models/Modgir.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace ApiSoftway.Models +{ + public class Modgir + { + [Key] + public string? Piprogre { get; set; } + public string? Piserial { get; set; } + public DateTime? Pidata { get; set; } + public string? Picommit { get; set; } + public string? Pidesdiv { get; set; } + public string? Pitarga { get; set; } + public string? Piautist { get; set; } + public string? Pitiprec { get; set; } + public string? Pirigele { get; set; } + } +} diff --git a/Models/Modgir_out.cs b/Models/Modgir_out.cs new file mode 100644 index 0000000..0cad2a2 --- /dev/null +++ b/Models/Modgir_out.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models +{ + [Keyless] + public class Modgir_out + { + public string? Piprogre { get; set; } + public string? Piserial { get; set; } + public DateTime? Pidata { get; set; } + public string? Picommit { get; set; } + public string? Pidesdiv { get; set; } + public string? Pitarga { get; set; } + public string? Piautist { get; set; } + public string? Pitiprec { get; set; } + public string? Pirigele { get; set; } + + /// errore titolo + public string? err_title { get; set; } + /// errore dettaglio + public string? err_detail { get; set; } + /// errore status code (200, 500) + public string? err_status_code { get; set; } + } +} diff --git a/Program.cs b/Program.cs index caa2202..66b2ac8 100644 --- a/Program.cs +++ b/Program.cs @@ -42,6 +42,9 @@ builder.Services.AddDbContext(options => options.UseSqlS 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