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);

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using System;
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Endpoint
@@ -17,24 +18,38 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Employee> ReadAllEmployees()
public IQueryable<Employee>? ReadAllEmployees()
{
return LogicServices.CRUDOperations.ReadAllEmployees();
try
{
return LogicServices.CRUDOperations.ReadAllEmployees();
}
catch (NullReferenceException)
{
return null;
}
}
[HttpGet("{id}")]
public Employee ReadEmployee(int id)
public Employee? ReadEmployee(int id)
{
return LogicServices.CRUDOperations.ReadEmployee(id);
try
{
return LogicServices.CRUDOperations.ReadEmployee(id);
}
catch (NullReferenceException)
{
return null;
}
}
[HttpPut()]
[HttpPut()]
public void PutEmployee([FromBody] Employee e)
{
LogicServices.CRUDOperations.CreateEmployee(e);
}
[HttpPost()]
[HttpPost()]
public void UpdateEmployee([FromBody] Employee e)
{
LogicServices.CRUDOperations.UpdateEmployee(e);

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using System;
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Endpoint
@@ -17,24 +18,38 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<MaintainerTeam> ReadAllMaintainerTeams()
public IQueryable<MaintainerTeam>? ReadAllMaintainerTeams()
{
return LogicServices.CRUDOperations.ReadAllMaintainerTeams();
try
{
return LogicServices.CRUDOperations.ReadAllMaintainerTeams();
}
catch (NullReferenceException)
{
return null;
}
}
[HttpGet("{id}")]
public MaintainerTeam ReadMaintainerTeam(int id)
public MaintainerTeam? ReadMaintainerTeam(int id)
{
return LogicServices.CRUDOperations.ReadMaintainerTeam(id);
try
{
return LogicServices.CRUDOperations.ReadMaintainerTeam(id);
}
catch (NullReferenceException)
{
return null;
}
}
[HttpPut()]
[HttpPut()]
public void PutMaintainerTeam([FromBody] MaintainerTeam e)
{
LogicServices.CRUDOperations.CreateMaintainerTeam(e);
}
[HttpPost()]
[HttpPost()]
public void UpdateMaintainerTeam([FromBody] MaintainerTeam e)
{
LogicServices.CRUDOperations.UpdateMaintainerTeam(e);

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using System;
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Endpoint
@@ -17,15 +18,29 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Service> ReadAllServices()
public IQueryable<Service>? ReadAllServices()
{
return LogicServices.CRUDOperations.ReadAllServices();
try
{
return LogicServices.CRUDOperations.ReadAllServices();
}
catch (NullReferenceException)
{
return null;
}
}
[HttpGet("{id}")]
public Service ReadService(int id)
public Service? ReadService(int id)
{
return LogicServices.CRUDOperations.ReadService(id);
try
{
return LogicServices.CRUDOperations.ReadService(id);
}
catch (NullReferenceException)
{
return null;
}
}
[HttpPut()]

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using WD7UVN_HFT_2023241.Models;
@@ -17,9 +18,16 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Employee> GetSubordinates([FromQuery] int id)
public IQueryable<Employee>? GetSubordinates([FromQuery] int id)
{
return LogicServices.GetSubordinates(id);
try
{
return LogicServices.GetSubordinates(id);
}
catch (NullReferenceException)
{
return null;
}
}
}
}

View File

@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Endpoint
@@ -17,9 +17,16 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public Employee WhoIsResponsibleForService([FromQuery] int id)
public Employee? WhoIsResponsibleForService([FromQuery] int id)
{
return LogicServices.WhoIsResponsibleForService(id);
try
{
return LogicServices.WhoIsResponsibleForService(id);
}
catch (NullReferenceException)
{
return null;
}
}
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using WD7UVN_HFT_2023241.Models;
@@ -17,9 +18,16 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Employee> WhoUsesService([FromQuery] int id)
public IQueryable<Employee>? WhoUsesService([FromQuery] int id)
{
return LogicServices.WhoMaintainsService(id);
try
{
return LogicServices.WhoMaintainsService(id);
}
catch (NullReferenceException)
{
return null;
}
}
}
}

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using System;
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Endpoint
@@ -17,9 +18,16 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Customer> WhoUsesService([FromQuery] int id)
public IQueryable<Customer>? WhoUsesService([FromQuery] int id)
{
return LogicServices.WhoUsesService(id);
try
{
return LogicServices.WhoUsesService(id);
}
catch (NullReferenceException)
{
return null;
}
}
}
}

View File

@@ -1,7 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using System;
using WD7UVN_HFT_2023241.Logic;
using System.Linq;
using WD7UVN_HFT_2023241.Models;
using Microsoft.AspNetCore.Mvc.Diagnostics;
namespace WD7UVN_HFT_2023241.Endpoint
{
@@ -17,9 +19,16 @@ namespace WD7UVN_HFT_2023241.Endpoint
}
[HttpGet()]
public IQueryable<Employee> WhoWorksInMaintainerTeam([FromQuery] int id)
public IQueryable<Employee>? WhoWorksInMaintainerTeam([FromQuery] int id)
{
return LogicServices.WhoWorksInMaintainerTeam(id);
try
{
return LogicServices.WhoWorksInMaintainerTeam(id);
}
catch (NullReferenceException)
{
return null;
}
}
}
}