Files
LaDOSE/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs

56 lines
1.2 KiB
C#
Raw Normal View History

2019-03-14 01:31:56 +01:00
using System;
using System.Collections.Generic;
2018-10-12 20:52:59 +02:00
using System.Linq;
using LaDOSE.Business.Interface;
using LaDOSE.Entity;
2019-03-14 01:31:56 +01:00
using Microsoft.AspNetCore.Authorization;
2018-10-12 20:52:59 +02:00
using Microsoft.AspNetCore.Mvc;
namespace LaDOSE.Api.Controllers
{
public abstract class GenericController<T, TU> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
2018-10-12 20:52:59 +02:00
{
protected T _service;
public GenericController(T service)
{
_service = service;
}
[HttpPost]
public virtual TU Post([FromBody] TU dto)
2018-10-12 20:52:59 +02:00
{
2019-03-09 14:03:25 +01:00
return _service.AddOrUpdate(dto);
2018-10-12 20:52:59 +02:00
}
2019-03-12 22:23:38 +01:00
2018-10-12 20:52:59 +02:00
[HttpGet]
public virtual List<TU> Get()
2018-10-12 20:52:59 +02:00
{
return _service.GetAll().ToList();
}
2019-03-12 22:23:38 +01:00
2018-10-12 20:52:59 +02:00
[HttpGet("{id}")]
public virtual TU Get(int id)
2018-10-12 20:52:59 +02:00
{
return _service.GetById(id);
}
2019-03-14 01:31:56 +01:00
2019-03-14 02:03:08 +01:00
[HttpDelete("{id}")]
public virtual IActionResult Delete(int id)
2019-03-14 01:31:56 +01:00
{
try
{
return _service.Delete((int) id) ? (IActionResult) NoContent() : NotFound();
}
catch (Exception)
{
return BadRequest();
}
}
2018-10-12 20:52:59 +02:00
}
}