forked from ddrilling/AsbCloudServer
71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[ApiController]
|
|
public abstract class CrudController<T> : ControllerBase
|
|
where T: IId
|
|
{
|
|
protected readonly ICrudService<T> service;
|
|
|
|
public CrudController(ICrudService<T> service)
|
|
{
|
|
this.service = service;
|
|
}
|
|
|
|
// GET: api/<CrudController>
|
|
//[HttpGet]
|
|
//public virtual IActionResult GetAll()
|
|
//{
|
|
// var result = service.GetAll();
|
|
// return Ok(result);
|
|
//}
|
|
|
|
// GET api/<CrudController>/5
|
|
[HttpGet("{id}")]
|
|
|
|
public virtual IActionResult Get(int id)
|
|
{
|
|
var result = service.Get(id);
|
|
return Ok(result);
|
|
}
|
|
|
|
// POST api/<CrudController>
|
|
[HttpPost]
|
|
public virtual IActionResult Insert([FromBody] T value)
|
|
{
|
|
var result = service.Insert(value);
|
|
return Ok(result);
|
|
}
|
|
|
|
//[HttpPost]
|
|
//[Route("Range/")]
|
|
//public virtual IActionResult InsertRange([FromBody] IEnumerable<T> value)
|
|
//{
|
|
// var result = service.InsertRange(value);
|
|
// return Ok(result);
|
|
//}
|
|
|
|
// PUT api/<CrudController>/5
|
|
[HttpPut("{id}")]
|
|
public virtual IActionResult Put(int id, [FromBody] T value)
|
|
{
|
|
var result = service.Update(value);
|
|
return Ok(result);
|
|
}
|
|
|
|
// DELETE api/<CrudController>/5
|
|
[HttpDelete("{id}")]
|
|
public virtual IActionResult Delete(int id)
|
|
{
|
|
var result = service.Delete(id);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
}
|