NewsController.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Mvc;
  7. using YiSha.Business.OrganizationManage;
  8. using YiSha.Entity.OrganizationManage;
  9. using YiSha.IBusiness.OrganizationManage;
  10. using YiSha.Model.Param;
  11. using YiSha.Model.Param.OrganizationManage;
  12. using YiSha.Util.Model;
  13. namespace YiSha.Admin.WebApi.Controllers
  14. {
  15. [Route("[controller]/[action]")]
  16. [ApiController]
  17. [AuthorizeFilter]
  18. public class NewsController : ControllerBase
  19. {
  20. private INewsBLL _newsBLL;
  21. public NewsController(INewsBLL newsBLL)
  22. {
  23. _newsBLL = newsBLL;
  24. }
  25. #region 获取数据
  26. /// <summary>
  27. /// 获取文章列表
  28. /// </summary>
  29. /// <param name="param"></param>
  30. /// <param name="pagination"></param>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public async Task<TData<List<NewsEntity>>> GetPageList([FromQuery] NewsListParam param, [FromQuery] Pagination pagination)
  34. {
  35. TData<List<NewsEntity>> obj = await _newsBLL.GetPageListPartial(param, pagination);
  36. return obj;
  37. }
  38. /// <summary>
  39. /// 获取文章列表
  40. /// </summary>
  41. /// <param name="param"></param>
  42. /// <param name="pagination"></param>
  43. /// <returns></returns>
  44. [HttpGet]
  45. public async Task<TData<List<NewsEntity>>> GetPageContentList([FromQuery] NewsListParam param, [FromQuery] Pagination pagination)
  46. {
  47. TData<List<NewsEntity>> obj = await _newsBLL.GetPageContentListPartial(param, pagination);
  48. return obj;
  49. }
  50. /// <summary>
  51. /// 获取文章内容
  52. /// </summary>
  53. /// <param name="id"></param>
  54. /// <returns></returns>
  55. [HttpGet]
  56. public async Task<TData<NewsEntity>> GetForm([FromQuery] int id)
  57. {
  58. TData<NewsEntity> obj = await _newsBLL.GetEntityPartial(id);
  59. return obj;
  60. }
  61. #endregion
  62. #region 提交数据
  63. /// <summary>
  64. /// 保存文章
  65. /// </summary>
  66. /// <param name="entity"></param>
  67. /// <returns></returns>
  68. [HttpPost]
  69. public async Task<TData<int>> SaveForm([FromBody] NewsEntity entity)
  70. {
  71. TData<int> obj = await _newsBLL.SaveFormPartial(entity);
  72. return obj;
  73. }
  74. [HttpPost]
  75. public async Task<TData<int>> SaveViewTimes([FromBody] IdParam param)
  76. {
  77. TData<int> obj = null;
  78. TData<NewsEntity> objNews = await _newsBLL.GetEntityPartial(param.Id);
  79. NewsEntity newsEntity = new NewsEntity();
  80. if (objNews.Data != null)
  81. {
  82. newsEntity.Id = param.Id;
  83. newsEntity.ViewTimes = objNews.Data.ViewTimes;
  84. newsEntity.ViewTimes++;
  85. obj = await _newsBLL.SaveFormPartial(newsEntity);
  86. }
  87. else
  88. {
  89. obj = new TData<int>();
  90. obj.Message = "文章不存在";
  91. }
  92. return obj;
  93. }
  94. #endregion
  95. }
  96. }