diff --git a/ApiAdHoc_Odoo/Controllers/ClientiController.cs b/ApiAdHoc_Odoo/Controllers/ClientiController.cs index 99c93a2..830dd53 100644 --- a/ApiAdHoc_Odoo/Controllers/ClientiController.cs +++ b/ApiAdHoc_Odoo/Controllers/ClientiController.cs @@ -18,18 +18,31 @@ namespace ApiAdHoc_Odoo.Controllers _clientiContext = clientiContext; } - //COMMENTATA PERCHE' L'IMPORT INIZIALE VERRA' FATTO DA FILE QUINDI NON CI SERVIRA' PIU' QUESTA CHIAMATA. - //// GET: api/ApiClienti - //[HttpGet("{codAzi}")] - //public async Task>> GetApiClienti(string codAzi) - //{ - // return await _clientiContext.Clienti.Where(x => x.Azienda == codAzi).ToListAsync(); - //} - [HttpGet("{pIva}")] public async Task>> GetApiClienti(string pIva) { - return await _clientiContext.Clienti.Where(x => x.Partiva == pIva).ToListAsync(); + + var clientiList = _clientiContext.Clienti.Where(x => x.Partiva == pIva).ToListAsync(); + + await foreach (var cliente in _clientiContext.Clienti.AsAsyncEnumerable()) + { + cliente.Azienda = cliente.Azienda.Trim(); + cliente.Codice = cliente.Codice.Trim(); + cliente.Descrizione = cliente.Descrizione.Trim(); + cliente.Partiva = cliente.Partiva.Trim(); + cliente.CodFisc = cliente.CodFisc.Trim(); + cliente.Telefono = cliente.Telefono.Trim(); + cliente.Cellulare = cliente.Cellulare.Trim(); + cliente.Email = cliente.Email.Trim(); + cliente.Indirizzo = cliente.Indirizzo.Trim(); + cliente.Citta = cliente.Citta.Trim(); + cliente.Cap = cliente.Cap.Trim(); + cliente.Provincia = cliente.Provincia.Trim(); + cliente.CodAgente = cliente.CodAgente.Trim(); + cliente.DescriAgente = cliente.DescriAgente.Trim(); + } + + return await clientiList; } // GET: api/ApiClienti/{codice} @@ -38,6 +51,21 @@ namespace ApiAdHoc_Odoo.Controllers { var cliente = await _clientiContext.Clienti.FirstOrDefaultAsync(c => c.Codice == codCli && c.Azienda == codAzi); + cliente.Azienda = cliente.Azienda.Trim(); + cliente.Codice = cliente.Codice.Trim(); + cliente.Descrizione = cliente.Descrizione.Trim(); + cliente.Partiva = cliente.Partiva.Trim(); + cliente.CodFisc = cliente.CodFisc.Trim(); + cliente.Telefono = cliente.Telefono.Trim(); + cliente.Cellulare = cliente.Cellulare.Trim(); + cliente.Email = cliente.Email.Trim(); + cliente.Indirizzo = cliente.Indirizzo.Trim(); + cliente.Citta = cliente.Citta.Trim(); + cliente.Cap = cliente.Cap.Trim(); + cliente.Provincia = cliente.Provincia.Trim(); + cliente.CodAgente = cliente.CodAgente.Trim(); + cliente.DescriAgente = cliente.DescriAgente.Trim(); + if (cliente == null) { return NotFound(); diff --git a/ApiAdHoc_Odoo/Controllers/FattureController.cs b/ApiAdHoc_Odoo/Controllers/FattureController.cs new file mode 100644 index 0000000..48697cb --- /dev/null +++ b/ApiAdHoc_Odoo/Controllers/FattureController.cs @@ -0,0 +1,41 @@ +using ApiAdHoc_Odoo.Data; +using ApiAdHoc_Odoo.Models; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ApiAdHoc_Odoo.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class FattureController : Controller + { + private readonly PI_FattureDbContext _fattureContext; + + public FattureController(PI_FattureDbContext fattureContext) + { + _fattureContext = fattureContext; + } + + //GET: lista fatture per azienda e cliente prendo quelle degli ultimi due anni ordinate per data più recente + [HttpGet("{codAzi}/{codCli}")] + public async Task>> GetApiFatture(string codAzi, string codCli) + { + var fattureList = _fattureContext.Fattura.Where(x => x.Azienda == codAzi && + x.CodCliente == codCli && + x.DataDocumento >= DateTime.Now.AddYears(-2)).OrderByDescending(x => x.DataDocumento).ToListAsync(); + + await foreach (var fattura in _fattureContext.Fattura.AsAsyncEnumerable()) + { + fattura.Azienda = fattura.Azienda.Trim(); + fattura.CodCliente = fattura.CodCliente.Trim(); + fattura.Descrizione = fattura.Descrizione.Trim(); + fattura.Classe = fattura.Classe.Trim(); + fattura.Documento = fattura.Azienda.Trim(); + } + + return await fattureList; + } + + } +} diff --git a/ApiAdHoc_Odoo/Data/PI_FattureDbContext.cs b/ApiAdHoc_Odoo/Data/PI_FattureDbContext.cs new file mode 100644 index 0000000..c464343 --- /dev/null +++ b/ApiAdHoc_Odoo/Data/PI_FattureDbContext.cs @@ -0,0 +1,20 @@ +using ApiAdHoc_Odoo.Models; +using Microsoft.EntityFrameworkCore; + +namespace ApiAdHoc_Odoo.Data +{ + public class PI_FattureDbContext : DbContext + { + public PI_FattureDbContext(DbContextOptions options) : base(options) { } + + public DbSet Fattura { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // Map the view to the model + modelBuilder.Entity() + .ToView("PI_APIFATTURE")/*;*/ + .HasNoKey(); // Views typically don't have a primary key + } + } +} diff --git a/ApiAdHoc_Odoo/Models/Fattura.cs b/ApiAdHoc_Odoo/Models/Fattura.cs new file mode 100644 index 0000000..046d3b8 --- /dev/null +++ b/ApiAdHoc_Odoo/Models/Fattura.cs @@ -0,0 +1,13 @@ +namespace ApiAdHoc_Odoo.Models +{ + public class Fattura + { + public string Azienda { get; set; } + public string CodCliente { get; set; } + public string Descrizione { get; set; } + public string Classe { get; set; } + public DateTime DataDocumento { get; set; } + public string Documento { get; set; } + public decimal Totale { get; set; } + } +} diff --git a/ApiAdHoc_Odoo/Program.cs b/ApiAdHoc_Odoo/Program.cs index b09fe1e..c5d9a9c 100644 --- a/ApiAdHoc_Odoo/Program.cs +++ b/ApiAdHoc_Odoo/Program.cs @@ -9,8 +9,12 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); #region istanze dbContext + builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); +builder.Services.AddDbContext(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); + #endregion builder.Services.AddControllers();