選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LuCrudController.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.ComponentModel.DataAnnotations;
  2. using Luticate2.Utils.Dbo.Basic;
  3. using Luticate2.Utils.Dbo.Filter;
  4. using Luticate2.Utils.Dbo.OrderBy;
  5. using Luticate2.Utils.Dbo.PaginatedRequest;
  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, TId> : LuController
  11. where TDboCreate : class
  12. where TDboRead : class
  13. where TDboUpdate : class
  14. where TBusiness : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
  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([Required]TId id)
  24. {
  25. return Handle(Busines.GetSingleById(id));
  26. }
  27. [HttpGet]
  28. [Route("[controller]")]
  29. public LuApiWrapperDbo<LuPaginatedDbo<TDboRead>> GetMultiple([Required]LuPaginatedRequestDbo request)
  30. {
  31. return Handle(Busines.GetMultiple(request.OrderBy, request.Filter, request.Page, request.PerPage));
  32. }
  33. [HttpPost]
  34. [Route("[controller]")]
  35. public LuApiWrapperDbo<TDboRead> AddDbo([FromBody][Required]TDboCreate data)
  36. {
  37. return Handle(Busines.AddDbo(data));
  38. }
  39. [HttpPost]
  40. [Route("[controller]/{id}")]
  41. public LuApiWrapperDbo<TDboRead> EditSingleByIdDbo([Required]TId id, [FromBody][Required]TDboUpdate data)
  42. {
  43. return Handle(Busines.EditSingleByIdDbo(id, data));
  44. }
  45. [HttpDelete]
  46. [Route("[controller]/{id}")]
  47. public LuApiWrapperDbo<TDboRead> Delete([Required]TId id)
  48. {
  49. return Handle(Busines.DeleteSingleByIdDbo(id));
  50. }
  51. }
  52. }