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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.ComponentModel.DataAnnotations;
  2. using Luticate2.Utils.Dbo.Basic;
  3. using Luticate2.Utils.Dbo.PaginatedRequest;
  4. using Luticate2.Utils.Interfaces;
  5. using Luticate2.Utils.Utils;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Options;
  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 Business;
  17. protected LuCrudController(TBusiness business, IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo) : base(luUtilsOptionsDbo)
  18. {
  19. Business = business;
  20. }
  21. [HttpGet]
  22. [Route("[controller]/{id}")]
  23. public virtual LuApiWrapperDbo<TDboRead> GetSingleById([Required]TId id)
  24. {
  25. return Handle(Business.GetSingleById(id));
  26. }
  27. [HttpGet]
  28. [Route("[controller]")]
  29. public virtual LuApiWrapperDbo<LuPaginatedDbo<TDboRead>> GetMultiple([Required]LuPaginatedRequestDbo request)
  30. {
  31. return Handle(Business.GetMultiple(request));
  32. }
  33. [HttpPost]
  34. [Route("[controller]")]
  35. public virtual LuApiWrapperDbo<TDboRead> AddDbo([FromBody][Required]TDboCreate data)
  36. {
  37. return Handle(Business.AddDbo(data));
  38. }
  39. [HttpPost]
  40. [Route("[controller]/{id}")]
  41. public virtual LuApiWrapperDbo<TDboRead> EditSingleByIdDbo([Required]TId id, [FromBody][Required]TDboUpdate data)
  42. {
  43. return Handle(Business.EditSingleByIdDbo(id, data));
  44. }
  45. [HttpDelete]
  46. [Route("[controller]/{id}")]
  47. public virtual LuApiWrapperDbo<TDboRead> Delete([Required]TId id)
  48. {
  49. return Handle(Business.DeleteSingleByIdDbo(id));
  50. }
  51. }
  52. }