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

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