Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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.Interfaces;
  6. using Microsoft.AspNetCore.Mvc;
  7. namespace Luticate2.Utils.Controllers
  8. {
  9. public abstract class LuCrudController<TBusiness, TDboCreate, TDboRead, TDboUpdate, TId> : LuController
  10. where TDboCreate : class
  11. where TDboRead : class
  12. where TDboUpdate : class
  13. where TBusiness : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
  14. {
  15. protected readonly TBusiness Busines;
  16. protected LuCrudController(TBusiness busines)
  17. {
  18. Busines = busines;
  19. }
  20. [HttpGet]
  21. [Route("[controller]/{id}")]
  22. public LuApiWrapperDbo<TDboRead> GetSingleById([Required]TId id)
  23. {
  24. return Handle(Busines.GetSingleById(id));
  25. }
  26. [HttpGet]
  27. [Route("[controller]")]
  28. public LuApiWrapperDbo<LuPaginatedDbo<TDboRead>> GetMultiple([Required]LuOrderByDbo orderBy, LuFilterDbo filter,
  29. int page = 0, int perPage = int.MaxValue)
  30. {
  31. return Handle(Busines.GetMultiple(orderBy, filter, page, 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. }