Exception handling

This commit is contained in:
2023-12-13 22:04:06 +01:00
parent 86cc431200
commit c112adc4d3
9 changed files with 133 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using WD7UVN_HFT_2023241.Models;
using System;
namespace WD7UVN_HFT_2023241.Endpoint
{
@@ -17,24 +18,38 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Customer> ReadAllCustomers()
public IQueryable<Customer>? ReadAllCustomers()
{
return LogicServices.CRUDOperations.ReadAllCustomers();
try
{
return LogicServices.CRUDOperations.ReadAllCustomers();
}
catch (NullReferenceException)
{
return null;
}
}
[HttpGet("{id}")]
public Customer ReadCustomer(int id)
public Customer? ReadCustomer(int id)
{
return LogicServices.CRUDOperations.ReadCustomer(id);
try
{
return LogicServices.CRUDOperations.ReadCustomer(id);
}
catch (NullReferenceException)
{
return null;
}
}
[HttpPut()]
[HttpPut()]
public void PutCustomer([FromBody] Customer e)
{
LogicServices.CRUDOperations.CreateCustomer(e);
}
[HttpPost()]
[HttpPost()]
public void UpdateCustomer([FromBody] Customer e)
{
LogicServices.CRUDOperations.UpdateCustomer(e);