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.8KB

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