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
|
|
|
|
|
|
{
|
2022-07-30 20:00:31 +02:00
|
|
|
|
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]
|
2022-07-30 20:00:31 +02:00
|
|
|
|
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]
|
2022-07-30 20:00:31 +02:00
|
|
|
|
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}")]
|
2022-07-30 20:00:31 +02:00
|
|
|
|
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}")]
|
2022-07-30 20:00:31 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|