AdminMediaController.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Common.Page;
  5. using GxPress.Repository.Interface.Media;
  6. using GxPress.Request.Media;
  7. using GxPress.Result.Media;
  8. using GxPress.Service.Interface.Media;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  12. namespace GxPress.Api.AdminControllers
  13. {
  14. [Route("api/admin/media")]
  15. [ApiController]
  16. [Authorize]
  17. public class AdminMediaController : Controller
  18. {
  19. private readonly IMediaRepository mediaRepository;
  20. private readonly ILoginContext _loginContext;
  21. private readonly IMediaService mediaService;
  22. public AdminMediaController(IMediaRepository mediaRepository, ILoginContext _loginContext, IMediaService mediaService)
  23. {
  24. this.mediaRepository = mediaRepository;
  25. this._loginContext = _loginContext;
  26. this.mediaService = mediaService;
  27. }
  28. /// <summary>
  29. /// 详情
  30. /// </summary>
  31. /// <param name="id"></param>
  32. /// <returns></returns>
  33. [HttpGet("{id}")]
  34. public async Task<MediaResult> GetAsync(int id)
  35. {
  36. return await mediaService.GetAsync(id);
  37. }
  38. /// <summary>
  39. /// 删除
  40. /// </summary>
  41. /// <param name="id"></param>
  42. /// <returns></returns>
  43. [HttpDelete("{id}")]
  44. public async Task<bool> DeleteAsync(int id)
  45. {
  46. return await mediaRepository.DeleteAsync(id);
  47. }
  48. /// <summary>
  49. /// 添加媒体
  50. /// </summary>
  51. /// <param name="result"></param>
  52. /// <returns></returns>
  53. [HttpPost]
  54. public async Task<bool> InsertAsync(MediaResult result)
  55. {
  56. result.AdminId = _loginContext.AccountId;
  57. result.Creator = _loginContext.Name;
  58. return await mediaService.InsertAsync(result);
  59. }
  60. /// <summary>
  61. /// 修改
  62. /// </summary>
  63. /// <param name="result"></param>
  64. /// <returns></returns>
  65. [HttpPut]
  66. public async Task<bool> UpdateAsync(MediaResult result)
  67. {
  68. return await mediaRepository.UpdateAsync(result);
  69. }
  70. /// <summary>
  71. /// 查询
  72. /// </summary>
  73. /// <param name="request"></param>
  74. /// <returns></returns>
  75. [HttpPost("list")]
  76. public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
  77. {
  78. return await mediaRepository.GetAllAsync(request);
  79. }
  80. }
  81. }