Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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 Busines;
  17. protected LuCrudController(TBusiness busines, IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo) : base(luUtilsOptionsDbo)
  18. {
  19. Busines = busines;
  20. }
  21. [HttpGet]
  22. [Route("[controller]/{id}")]
  23. public virtual LuApiWrapperDbo<TDboRead> GetSingleById([Required]TId id)
  24. {
  25. return Handle(Busines.GetSingleById(id));
  26. }
  27. [HttpGet]
  28. [Route("[controller]")]
  29. public virtual LuApiWrapperDbo<LuPaginatedDbo<TDboRead>> GetMultiple([Required]LuPaginatedRequestDbo request)
  30. {
  31. return Handle(Busines.GetMultiple(request));
  32. }
  33. [HttpPost]
  34. [Route("[controller]")]
  35. public virtual LuApiWrapperDbo<TDboRead> AddDbo([FromBody][Required]TDboCreate data)
  36. {
  37. return Handle(Busines.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(Busines.EditSingleByIdDbo(id, data));
  44. }
  45. [HttpDelete]
  46. [Route("[controller]/{id}")]
  47. public virtual LuApiWrapperDbo<TDboRead> Delete([Required]TId id)
  48. {
  49. return Handle(Busines.DeleteSingleByIdDbo(id));
  50. }
  51. }
  52. }