AdminMediaController.cs 2.5 KB

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