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 WD7UVN_HFT_2023241.Logic;
using System.Linq; using System.Linq;
using WD7UVN_HFT_2023241.Models; using WD7UVN_HFT_2023241.Models;
using System;
namespace WD7UVN_HFT_2023241.Endpoint namespace WD7UVN_HFT_2023241.Endpoint
{ {
@@ -17,16 +18,30 @@ namespace WD7UVN_HFT_2023241.Endpoint
} }
[HttpGet()] [HttpGet()]
public IQueryable<Customer> ReadAllCustomers() public IQueryable<Customer>? ReadAllCustomers()
{
try
{ {
return LogicServices.CRUDOperations.ReadAllCustomers(); return LogicServices.CRUDOperations.ReadAllCustomers();
} }
catch (NullReferenceException)
{
return null;
}
}
[HttpGet("{id}")] [HttpGet("{id}")]
public Customer ReadCustomer(int id) public Customer? ReadCustomer(int id)
{
try
{ {
return LogicServices.CRUDOperations.ReadCustomer(id); return LogicServices.CRUDOperations.ReadCustomer(id);
} }
catch (NullReferenceException)
{
return null;
}
}
[HttpPut()] [HttpPut()]
public void PutCustomer([FromBody] Customer e) public void PutCustomer([FromBody] Customer e)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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