diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index 6f94ca3..b2b161d 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -385,7 +385,6 @@ namespace ApiPolo.Controllers #region VT - Tecnici private readonly VT_TECNICI_TABLE_DbContext _VT_tectable; private readonly VT_TECNICI_DbContext _VT_tec; - private readonly VT_ARTICOLI_TABLE_DbContext _vt_artTable; #endregion #region VT - anagrafiche @@ -455,6 +454,10 @@ namespace ApiPolo.Controllers private readonly VT_TIMBRATURE_DbContext _VT_timbr; #endregion + #region VT-ARTICOLI + private readonly VT_ARTICOLI_TABLE_DbContext _VT_articoliTable; + #endregion + #region Commesse desc private readonly SIET_COMMESSE_DESC_DbContext _Siet_commDesc; private readonly MARRO_COMMESSE_TABLE_DbContext _Marro_commDesc; @@ -505,6 +508,7 @@ namespace ApiPolo.Controllers private DbSet? _VT_rapport; private DbSet? _VT_buo; private DbSet? _rapp_new_view; + private DbSet? _articoliTable; private DbSet? _commDesc; private DbSet? _commDescSiet; @@ -873,11 +877,9 @@ namespace ApiPolo.Controllers VT_RAPPORTINI_DbContext VT_Rapportini, VT_Buoni_DbContext VT_Buoni, VT_STO_RAPP_DbContext VT_StoRapp, - VT_TIMBRATURE_DbContext VT_timbr + VT_TIMBRATURE_DbContext VT_timbr, + VT_ARTICOLI_TABLE_DbContext VT_artTable #endregion - - - ) { _configuration = configuration; @@ -1221,7 +1223,7 @@ namespace ApiPolo.Controllers _VT_Rapportini = VT_Rapportini; _VT_Buoni = VT_Buoni; _VT_StoRapp = VT_StoRapp; - + _VT_articoliTable = VT_artTable; #endregion #region Commesse desc @@ -15297,6 +15299,111 @@ namespace ApiPolo.Controllers } } + /// VIRTUAL TASK: lista articoli per azienda + [HttpGet("articoliList")] + public async Task>> ArticoliList(string token) + { + try + { + List alist = new List(); + string ten = getClaimValueByToken(token, "tenant2"); + string tecnico = getClaimValueByToken(token, "tccodice"); + _articoliTable = _VT_articoliTable.Articoli; + + var art = await _articoliTable.Where(x => x.Azienda.Equals(ten)).ToListAsync(); + + foreach (Articoli a in art) + { + alist.Add(a); + } + return StatusCode(StatusCodes.Status200OK, alist); + } + catch (Exception ex) + { + string err = "Errore: " + ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, err); ; + } + } + + /// VIRTUAL TASK : crea nuovo articolo return: ActionResult + [HttpPost] + [Route("articolo/add")] + public async Task> addArticolo([FromBody] Articoli model, string token) + { + string ten = getClaimValueByToken(token, "tenant2"); + model.Azienda = ten; + try + { + using (var transaction = _VT_articoliTable.Database.BeginTransaction()) + { + await _VT_articoliTable.Articoli.AddAsync(model); + await _VT_articoliTable.SaveChangesAsync(); + transaction.Commit(); + } + return StatusCode(StatusCodes.Status200OK, model); + + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, errmsg); ; + } + } + + /// VIRTUAL TASK : modifica articolo return: ActionResult + [HttpPost] + [Route("articolo/mod")] + public async Task> modArticolo([FromBody] Articoli model, string token) + { + string ten = getClaimValueByToken(token, "tenant2"); + model.Azienda = ten; + + try + { + using (var transaction = _VT_articoliTable.Database.BeginTransaction()) + { + _VT_articoliTable.Entry(model).State = EntityState.Modified; + await _VT_articoliTable.SaveChangesAsync(); + transaction.Commit(); + } + return StatusCode(StatusCodes.Status200OK, model); + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, errmsg); + } + } + + /// VIRTUAL TASK: cancella un articolo return:ActionResult + [HttpPost] + [Route("articolo/del")] + public async Task> delArticolo(string artcodice, string token) + { + string ten = getClaimValueByToken(token, "tenant2"); + _articoliTable = _VT_articoliTable.Articoli; + var art = await _articoliTable.Where(a => a.SlCodice.Equals(artcodice) && a.Azienda.Equals(ten)).ToListAsync(); + + Articoli model = art.First(); + //model.dataCanc = DateTime.Now; + + try + { + using (var transaction = _VT_articoliTable.Database.BeginTransaction()) + { + _VT_articoliTable.Entry(model).State = EntityState.Modified; + await _VT_articoliTable.SaveChangesAsync(); + transaction.Commit(); + } + return StatusCode(StatusCodes.Status200OK, model); + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + return StatusCode(StatusCodes.Status500InternalServerError, errmsg); + } + } + #endregion #region Logging diff --git a/ApiPolo/Models/Articoli.cs b/ApiPolo/Models/Articoli.cs index 9cf8d14..ed458c8 100644 --- a/ApiPolo/Models/Articoli.cs +++ b/ApiPolo/Models/Articoli.cs @@ -29,8 +29,8 @@ namespace ApiPolo.Models public decimal? LiScont3 { get; set; } [Column(TypeName = "decimal(6,2)")] public decimal? LiScont4 { get; set; } - public string? GestMatr { get; set; } - public string? GestLotti { get; set; } - public string? DescSup { get; set; } + public string? GEST_MATR { get; set; } + public string? GEST_LOTTI { get; set; } + public string? DESC_SUP { get; set; } } } diff --git a/ApiPolo/Models/VT_dbcontext/VT_ARTICOLI_TABLE_DbContext.cs b/ApiPolo/Models/VT_dbcontext/VT_ARTICOLI_TABLE_DbContext.cs index 607f1fc..d04cf7b 100644 --- a/ApiPolo/Models/VT_dbcontext/VT_ARTICOLI_TABLE_DbContext.cs +++ b/ApiPolo/Models/VT_dbcontext/VT_ARTICOLI_TABLE_DbContext.cs @@ -16,14 +16,13 @@ namespace ApiPolo.Models.VT_dbcontext protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().ToTable("Articoli"); + modelBuilder.Entity().ToTable("ARTICOLI"); modelBuilder.Entity().HasKey(Table => new { - Table.Azienda, + Table.Azienda, Table.SlCodice }); // Definizione della chiave primaria composta - - base.OnModelCreating(modelBuilder); + //base.OnModelCreating(modelBuilder); } }