Aggiunto errore 404 con messaggio su tutti i controller
This commit is contained in:
parent
a669898eb0
commit
d2ff29f1b6
@ -20,9 +20,15 @@ namespace ApiAdHoc_Odoo.Controllers
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Articolo>>> GetApiArticoli()
|
||||
{
|
||||
var articoliList = _articoliContext.Articolo.ToListAsync();
|
||||
var articoliList = await _articoliContext.Articolo.ToListAsync();
|
||||
|
||||
return await articoliList;
|
||||
if (articoliList == null || !articoliList.Any())
|
||||
{
|
||||
//return NotFound(); // Restituisce 404 se la lista è vuota
|
||||
return NotFound(new { message = "Nessun articolo trovato." }); // Restituisce 404 con un messaggio
|
||||
}
|
||||
|
||||
return articoliList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,7 +21,16 @@ namespace ApiAdHoc_Odoo.Controllers
|
||||
[HttpGet("{pIva}")]
|
||||
public async Task<ActionResult<IEnumerable<Cliente>>> GetApiClienti(string pIva)
|
||||
{
|
||||
return await _clientiContext.Clienti.Where(x => x.Partiva == pIva).ToListAsync();
|
||||
|
||||
var clientiList = await _clientiContext.Clienti.Where(x => x.Partiva == pIva).ToListAsync();
|
||||
|
||||
if (clientiList == null || !clientiList.Any())
|
||||
{
|
||||
//return NotFound(); // Restituisce 404 se la lista è vuota
|
||||
return NotFound(new { message = $"Nessun cliente trovato con Partita IVA: {pIva.Trim()}." });
|
||||
}
|
||||
|
||||
return clientiList;
|
||||
|
||||
}
|
||||
|
||||
@ -33,13 +42,11 @@ namespace ApiAdHoc_Odoo.Controllers
|
||||
|
||||
if (cliente == null)
|
||||
{
|
||||
return NotFound();
|
||||
//return NotFound();
|
||||
return NotFound(new { message = $"Nessun cliente trovato con Codice: '{codCli.Trim()}' per Azienda: '{codAzi.Trim()}'." });
|
||||
}
|
||||
|
||||
return cliente;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,11 +21,18 @@ namespace ApiAdHoc_Odoo.Controllers
|
||||
[HttpGet("{codAzi}/{codCli}")]
|
||||
public async Task<ActionResult<IEnumerable<Fattura>>> GetApiFatture(string codAzi, string codCli)
|
||||
{
|
||||
var fattureList = _fattureContext.Fattura.Where(x => x.Azienda == codAzi &&
|
||||
var fattureList = await _fattureContext.Fattura.Where(x => x.Azienda == codAzi &&
|
||||
x.CodCliente == codCli &&
|
||||
x.DataDocumento >= DateTime.Now.AddYears(-2)).OrderByDescending(x => x.DataDocumento).ToListAsync();
|
||||
|
||||
return await fattureList;
|
||||
if (fattureList == null || !fattureList.Any())
|
||||
{
|
||||
//return NotFound(); // Restituisce 404 se la lista è vuota
|
||||
return NotFound(new { message = $"Nessuna fattura trovata per il cliente: '{codCli.Trim()}' per Azienda: '{codAzi.Trim()}'." });
|
||||
|
||||
}
|
||||
|
||||
return fattureList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,10 +20,17 @@ namespace ApiAdHoc_Odoo.Controllers
|
||||
[HttpGet("{codAzi}/{codCli}")]
|
||||
public async Task<ActionResult<IEnumerable<Scadenze>>> GetApiScadenze(string codAzi, string codCli)
|
||||
{
|
||||
var scadenzeList = _scadenzeContext.Scadenza.
|
||||
var scadenzeList = await _scadenzeContext.Scadenza.
|
||||
Where(x => x.Azienda == codAzi && x.Cliente == codCli).OrderBy(x => x.Scadenza).ToListAsync();
|
||||
|
||||
return await scadenzeList;
|
||||
if (scadenzeList == null || !scadenzeList.Any())
|
||||
{
|
||||
//return NotFound(); // Restituisce 404 se la lista è vuota
|
||||
return NotFound(new { message = $"Nessuna partita trovata per il cliente: '{codCli.Trim()}' per Azienda: '{codAzi.Trim()}'." });
|
||||
|
||||
}
|
||||
|
||||
return scadenzeList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user