Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LuCrudController.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. using Microsoft.Extensions.Options;
  9. namespace Luticate2.Utils.Controllers
  10. {
  11. public abstract class LuCrudController<TBusiness, TDboCreate, TDboRead, TDboUpdate, TId> : LuController
  12. where TDboCreate : class
  13. where TDboRead : class
  14. where TDboUpdate : class
  15. where TBusiness : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
  16. {
  17. protected readonly TBusiness Busines;
  18. protected LuCrudController(TBusiness busines, IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo) : base(luUtilsOptionsDbo)
  19. {
  20. Busines = busines;
  21. }
  22. [HttpGet]
  23. [Route("[controller]/{id}")]
  24. public virtual LuApiWrapperDbo<TDboRead> GetSingleById([Required]TId id)
  25. {
  26. return Handle(Busines.GetSingleById(id));
  27. }
  28. [HttpGet]
  29. [Route("[controller]")]
  30. public virtual LuApiWrapperDbo<LuPaginatedDbo<TDboRead>> GetMultiple([Required]LuPaginatedRequestDbo request)
  31. {
  32. return Handle(Busines.GetMultiple(request.OrderBy, request.Filter, request.Page, request.PerPage));
  33. }
  34. [HttpPost]
  35. [Route("[controller]")]
  36. public virtual LuApiWrapperDbo<TDboRead> AddDbo([FromBody][Required]TDboCreate data)
  37. {
  38. return Handle(Busines.AddDbo(data));
  39. }
  40. [HttpPost]
  41. [Route("[controller]/{id}")]
  42. public virtual LuApiWrapperDbo<TDboRead> EditSingleByIdDbo([Required]TId id, [FromBody][Required]TDboUpdate data)
  43. {
  44. return Handle(Busines.EditSingleByIdDbo(id, data));
  45. }
  46. [HttpDelete]
  47. [Route("[controller]/{id}")]
  48. public virtual LuApiWrapperDbo<TDboRead> Delete([Required]TId id)
  49. {
  50. return Handle(Busines.DeleteSingleByIdDbo(id));
  51. }
  52. }
  53. }