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
{
2019-03-12 22:23:38 +01:00
public 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]
2019-03-12 22:23:38 +01:00
public 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 List<TU> Get()
{
return _service.GetAll().ToList();
}
2019-03-12 22:23:38 +01:00
2018-10-12 20:52:59 +02:00
[HttpGet("{id}")]
public TU Get(int id)
{
return _service.GetById(id);
}
2019-03-14 01:31:56 +01:00
[HttpGet("{id}/delete")]
public IActionResult Delete(int id)
{
try
{
return _service.Delete((int) id) ? (IActionResult) NoContent() : NotFound();
}
catch (Exception)
{
return BadRequest();
}
}
2018-10-12 20:52:59 +02:00
}
}