articoli operazioni crud + db context e model
This commit is contained in:
parent
88b42381a9
commit
ba1bce42e6
@ -385,7 +385,6 @@ namespace ApiPolo.Controllers
|
|||||||
#region VT - Tecnici
|
#region VT - Tecnici
|
||||||
private readonly VT_TECNICI_TABLE_DbContext _VT_tectable;
|
private readonly VT_TECNICI_TABLE_DbContext _VT_tectable;
|
||||||
private readonly VT_TECNICI_DbContext _VT_tec;
|
private readonly VT_TECNICI_DbContext _VT_tec;
|
||||||
private readonly VT_ARTICOLI_TABLE_DbContext _vt_artTable;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region VT - anagrafiche
|
#region VT - anagrafiche
|
||||||
@ -455,6 +454,10 @@ namespace ApiPolo.Controllers
|
|||||||
private readonly VT_TIMBRATURE_DbContext _VT_timbr;
|
private readonly VT_TIMBRATURE_DbContext _VT_timbr;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region VT-ARTICOLI
|
||||||
|
private readonly VT_ARTICOLI_TABLE_DbContext _VT_articoliTable;
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Commesse desc
|
#region Commesse desc
|
||||||
private readonly SIET_COMMESSE_DESC_DbContext _Siet_commDesc;
|
private readonly SIET_COMMESSE_DESC_DbContext _Siet_commDesc;
|
||||||
private readonly MARRO_COMMESSE_TABLE_DbContext _Marro_commDesc;
|
private readonly MARRO_COMMESSE_TABLE_DbContext _Marro_commDesc;
|
||||||
@ -505,6 +508,7 @@ namespace ApiPolo.Controllers
|
|||||||
private DbSet<Rapportino>? _VT_rapport;
|
private DbSet<Rapportino>? _VT_rapport;
|
||||||
private DbSet<Buoni>? _VT_buo;
|
private DbSet<Buoni>? _VT_buo;
|
||||||
private DbSet<Rapp_New_View>? _rapp_new_view;
|
private DbSet<Rapp_New_View>? _rapp_new_view;
|
||||||
|
private DbSet<Articoli>? _articoliTable;
|
||||||
|
|
||||||
private DbSet<CommessaDesc>? _commDesc;
|
private DbSet<CommessaDesc>? _commDesc;
|
||||||
private DbSet<CommessaDescSiet>? _commDescSiet;
|
private DbSet<CommessaDescSiet>? _commDescSiet;
|
||||||
@ -873,11 +877,9 @@ namespace ApiPolo.Controllers
|
|||||||
VT_RAPPORTINI_DbContext VT_Rapportini,
|
VT_RAPPORTINI_DbContext VT_Rapportini,
|
||||||
VT_Buoni_DbContext VT_Buoni,
|
VT_Buoni_DbContext VT_Buoni,
|
||||||
VT_STO_RAPP_DbContext VT_StoRapp,
|
VT_STO_RAPP_DbContext VT_StoRapp,
|
||||||
VT_TIMBRATURE_DbContext VT_timbr
|
VT_TIMBRATURE_DbContext VT_timbr,
|
||||||
|
VT_ARTICOLI_TABLE_DbContext VT_artTable
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
@ -1221,7 +1223,7 @@ namespace ApiPolo.Controllers
|
|||||||
_VT_Rapportini = VT_Rapportini;
|
_VT_Rapportini = VT_Rapportini;
|
||||||
_VT_Buoni = VT_Buoni;
|
_VT_Buoni = VT_Buoni;
|
||||||
_VT_StoRapp = VT_StoRapp;
|
_VT_StoRapp = VT_StoRapp;
|
||||||
|
_VT_articoliTable = VT_artTable;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Commesse desc
|
#region Commesse desc
|
||||||
@ -15297,6 +15299,111 @@ namespace ApiPolo.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>VIRTUAL TASK: lista articoli per azienda</summary>
|
||||||
|
[HttpGet("articoliList")]
|
||||||
|
public async Task<ActionResult<IEnumerable<Articoli>>> ArticoliList(string token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<Articoli> alist = new List<Articoli>();
|
||||||
|
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); ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///<summary> VIRTUAL TASK : crea nuovo articolo return: ActionResult</summary>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("articolo/add")]
|
||||||
|
public async Task<ActionResult<Articoli>> 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); ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///<summary> VIRTUAL TASK : modifica articolo return: ActionResult</summary>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("articolo/mod")]
|
||||||
|
public async Task<ActionResult<Articoli>> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>VIRTUAL TASK: cancella un articolo return:ActionResult</summary>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("articolo/del")]
|
||||||
|
public async Task<ActionResult<Articoli>> 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
|
#endregion
|
||||||
|
|
||||||
#region Logging
|
#region Logging
|
||||||
|
|||||||
@ -29,8 +29,8 @@ namespace ApiPolo.Models
|
|||||||
public decimal? LiScont3 { get; set; }
|
public decimal? LiScont3 { get; set; }
|
||||||
[Column(TypeName = "decimal(6,2)")]
|
[Column(TypeName = "decimal(6,2)")]
|
||||||
public decimal? LiScont4 { get; set; }
|
public decimal? LiScont4 { get; set; }
|
||||||
public string? GestMatr { get; set; }
|
public string? GEST_MATR { get; set; }
|
||||||
public string? GestLotti { get; set; }
|
public string? GEST_LOTTI { get; set; }
|
||||||
public string? DescSup { get; set; }
|
public string? DESC_SUP { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,14 +16,13 @@ namespace ApiPolo.Models.VT_dbcontext
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Articoli>().ToTable("Articoli");
|
modelBuilder.Entity<Articoli>().ToTable("ARTICOLI");
|
||||||
modelBuilder.Entity<Articoli>().HasKey(Table => new
|
modelBuilder.Entity<Articoli>().HasKey(Table => new
|
||||||
{
|
{
|
||||||
Table.Azienda,
|
Table.Azienda,
|
||||||
Table.SlCodice
|
Table.SlCodice
|
||||||
}); // Definizione della chiave primaria composta
|
}); // Definizione della chiave primaria composta
|
||||||
|
//base.OnModelCreating(modelBuilder);
|
||||||
base.OnModelCreating(modelBuilder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user