Code-complete v2 vehicle API
This commit is contained in:
35
PartSource.Api/Controllers/BaseApiController.cs
Normal file
35
PartSource.Api/Controllers/BaseApiController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace PartSource.Api.Controllers
|
||||
{
|
||||
public class BaseApiController : ControllerBase
|
||||
{
|
||||
public ActionResult ApiResponse<T>(T response)
|
||||
{
|
||||
switch (response)
|
||||
{
|
||||
case IList list:
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (response == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user