You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuCrudController.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Luticate2.Utils.Dbo;
  2. using Luticate2.Utils.Dbo.OrderBy;
  3. using Luticate2.Utils.Interfaces;
  4. using Microsoft.AspNetCore.Mvc;
  5. namespace Luticate2.Utils.Controllers
  6. {
  7. public abstract class LuCrudController<TDboCreate, TDboRead, TDboUpdate> : LuController
  8. where TDboCreate : class
  9. where TDboRead : class
  10. where TDboUpdate : class
  11. {
  12. protected readonly ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate> Busines;
  13. protected LuCrudController(ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate> busines)
  14. {
  15. Busines = busines;
  16. }
  17. [HttpGet]
  18. [Route("[controller]/{id}")]
  19. public TDboRead GetSingleById(string id)
  20. {
  21. return Handle(Busines.GetSingleById(id));
  22. }
  23. [HttpGet]
  24. [Route("[controller]")]
  25. public LuPaginatedDbo<TDboRead> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
  26. {
  27. return Handle(Busines.GetMultiple(orderBy, page, perPage));
  28. }
  29. [HttpPost]
  30. [Route("[controller]")]
  31. public TDboRead Add([FromBody]TDboCreate data)
  32. {
  33. return Handle(Busines.AddDbo(data));
  34. }
  35. [HttpPost]
  36. [Route("[controller]/{id}")]
  37. public TDboRead Edit(string id, [FromBody]TDboUpdate data)
  38. {
  39. return Handle(Busines.EditSingleByIdDbo(id, data));
  40. }
  41. [HttpDelete]
  42. [Route("[controller]/{id}")]
  43. public TDboRead Delete(string id)
  44. {
  45. return Handle(Busines.DeleteSingleByIdDbo(id));
  46. }
  47. }
  48. }