Compare commits
2 Commits
946b6cf6b5
...
7cd0837a8d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cd0837a8d | ||
|
|
dfaba8b903 |
@ -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<ActionResult<IEnumerable<Cliente>>> GetApiClienti(string codAzi)
|
||||
//{
|
||||
// return await _clientiContext.Clienti.Where(x => x.Azienda == codAzi).ToListAsync();
|
||||
//}
|
||||
|
||||
[HttpGet("{pIva}")]
|
||||
public async Task<ActionResult<IEnumerable<Cliente>>> 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();
|
||||
|
||||
41
ApiAdHoc_Odoo/Controllers/FattureController.cs
Normal file
41
ApiAdHoc_Odoo/Controllers/FattureController.cs
Normal file
@ -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<ActionResult<IEnumerable<Fattura>>> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
20
ApiAdHoc_Odoo/Data/PI_FattureDbContext.cs
Normal file
20
ApiAdHoc_Odoo/Data/PI_FattureDbContext.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using ApiAdHoc_Odoo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiAdHoc_Odoo.Data
|
||||
{
|
||||
public class PI_FattureDbContext : DbContext
|
||||
{
|
||||
public PI_FattureDbContext(DbContextOptions<PI_FattureDbContext> options) : base(options) { }
|
||||
|
||||
public DbSet<Fattura> Fattura { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
// Map the view to the model
|
||||
modelBuilder.Entity<Fattura>()
|
||||
.ToView("PI_APIFATTURE")/*;*/
|
||||
.HasNoKey(); // Views typically don't have a primary key
|
||||
}
|
||||
}
|
||||
}
|
||||
13
ApiAdHoc_Odoo/Models/Fattura.cs
Normal file
13
ApiAdHoc_Odoo/Models/Fattura.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -13,8 +13,12 @@ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtoc
|
||||
builder.Services.AddControllers();
|
||||
|
||||
#region istanze dbContext
|
||||
|
||||
builder.Services.AddDbContext<Pi_ClientiDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
builder.Services.AddDbContext<PI_FattureDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
#endregion
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user