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.

LuFsFilesCrudController.cs 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.ComponentModel.DataAnnotations;
  2. using Luticate2.Utils.Dbo.Basic;
  3. using Luticate2.Utils.Dbo.FsFiles;
  4. using Luticate2.Utils.Dbo.PaginatedRequest;
  5. using Luticate2.Utils.Interfaces;
  6. using Luticate2.Utils.Utils;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Options;
  10. namespace Luticate2.Utils.Controllers
  11. {
  12. public class LuFsFilesCrudController<TBusiness> : LuController
  13. where TBusiness : ILuCrudInterface<LuFsFilesAddDbo, LuFsFilesDbo, LuFsFilesAddDbo, string>
  14. {
  15. protected readonly TBusiness Business;
  16. public LuFsFilesCrudController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo, TBusiness business) : base(luUtilsOptionsDbo)
  17. {
  18. Business = business;
  19. }
  20. [HttpGet]
  21. [Route("[controller]/{id}")]
  22. public virtual LuApiWrapperDbo<LuFsFilesDbo> GetSingleById([Required]string id)
  23. {
  24. return Handle(Business.GetSingleById(id));
  25. }
  26. [HttpPost]
  27. [Route("[controller]")]
  28. public LuApiWrapperDbo<LuFsFilesDbo> AddDbo([Required]IFormFile file, string path)
  29. {
  30. return Handle(Business.AddDbo(new LuFsFilesAddDbo
  31. {
  32. File = file.OpenReadStream(),
  33. Path = string.IsNullOrEmpty(path) ? file.FileName : path
  34. }));
  35. }
  36. [HttpGet]
  37. [Route("[controller]")]
  38. public virtual LuApiWrapperDbo<LuPaginatedDbo<LuFsFilesDbo>> GetMultiple([Required]LuPaginatedRequestDbo request)
  39. {
  40. return Handle(Business.GetMultiple(request));
  41. }
  42. [HttpPost]
  43. [Route("[controller]/{id}")]
  44. public virtual LuApiWrapperDbo<LuFsFilesDbo> EditSingleByIdDbo([Required]string id, IFormFile file, string path)
  45. {
  46. return Handle(Business.EditSingleByIdDbo(id, new LuFsFilesAddDbo
  47. {
  48. File = file?.OpenReadStream(),
  49. Path = path
  50. }));
  51. }
  52. [HttpDelete]
  53. [Route("[controller]/{id}")]
  54. public virtual LuApiWrapperDbo<LuFsFilesDbo> Delete([Required]string id)
  55. {
  56. return Handle(Business.DeleteSingleByIdDbo(id));
  57. }
  58. }
  59. }