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.
 
 
 
 
 
 

193 lines
5.8 KiB

  1. using Learun.Application.Base.SystemModule;
  2. using Learun.Application.Extention.PortalSiteManage;
  3. using Learun.Util;
  4. using System;
  5. using System.IO;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. namespace Learun.Application.Web.Areas.LR_PortalSite.Controllers
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  12. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2018-09-05 09:35
  15. /// 描 述:详细信息维护
  16. /// </summary>
  17. public class ArticleController : MvcControllerBase
  18. {
  19. private ArticleIBLL articleIBLL = new ArticleBLL();
  20. private ImgIBLL imgIBLL = new ImgBLL();
  21. #region 视图功能
  22. /// <summary>
  23. /// 主页面
  24. /// <summary>
  25. /// <returns></returns>
  26. [HttpGet]
  27. public ActionResult Index()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 表单页
  33. /// <summary>
  34. /// <returns></returns>
  35. [HttpGet]
  36. public ActionResult Form()
  37. {
  38. return View();
  39. }
  40. #endregion
  41. #region 获取数据
  42. /// <summary>
  43. /// 获取列表数据
  44. /// <summary>
  45. /// <returns></returns>
  46. [HttpGet]
  47. [AjaxOnly]
  48. public ActionResult GetList( string queryJson )
  49. {
  50. var data = articleIBLL.GetList(queryJson);
  51. return Success(data);
  52. }
  53. /// <summary>
  54. /// 获取列表分页数据
  55. /// <param name="pagination">分页参数</param>
  56. /// <summary>
  57. /// <returns></returns>
  58. [HttpGet]
  59. [AjaxOnly]
  60. public ActionResult GetPageList(string pagination, string queryJson)
  61. {
  62. Pagination paginationobj = pagination.ToObject<Pagination>();
  63. var data = articleIBLL.GetPageList(paginationobj, queryJson);
  64. var jsonData = new
  65. {
  66. rows = data,
  67. total = paginationobj.total,
  68. page = paginationobj.page,
  69. records = paginationobj.records
  70. };
  71. return Success(jsonData);
  72. }
  73. /// <summary>
  74. /// 获取表单数据
  75. /// <param name="keyValue">主键</param>
  76. /// <summary>
  77. /// <returns></returns>
  78. [HttpGet]
  79. [AjaxOnly]
  80. public ActionResult GetFormData(string keyValue)
  81. {
  82. var data = articleIBLL.GetEntity(keyValue);
  83. return Success(data);
  84. }
  85. #endregion
  86. #region 提交数据
  87. /// <summary>
  88. /// 删除实体数据
  89. /// <param name="keyValue">主键</param>
  90. /// <summary>
  91. /// <returns></returns>
  92. [HttpPost]
  93. [AjaxOnly]
  94. public ActionResult DeleteForm(string keyValue)
  95. {
  96. string[] content = keyValue.Split(',');
  97. foreach (var item in content)
  98. {
  99. var entity = articleIBLL.GetEntity(item);
  100. articleIBLL.DeleteEntity(item);
  101. if (!string.IsNullOrEmpty(entity.F_Img)) {
  102. imgIBLL.DeleteEntity(entity.F_Img);
  103. }
  104. }
  105. return Success("删除成功!");
  106. }
  107. /// <summary>
  108. /// 保存实体数据(新增、修改)
  109. /// <param name="keyValue">主键</param>
  110. /// <summary>
  111. /// <returns></returns>
  112. [HttpPost]
  113. [ValidateAntiForgeryToken]
  114. [AjaxOnly, ValidateInput(false)]
  115. public ActionResult SaveForm(string keyValue,ArticleEntity entity)
  116. {
  117. articleIBLL.SaveEntity(keyValue, entity);
  118. return Success("保存成功!");
  119. }
  120. /// <summary>
  121. /// 保存图片和存储数据
  122. /// </summary>
  123. /// <param name="keyValue">主键</param>
  124. /// <param name="entity">实体</param>
  125. /// <returns></returns>
  126. [ValidateInput(false)]
  127. [HttpPost]
  128. public ActionResult UploadFile(string keyValue, ArticleEntity entity)
  129. {
  130. entity.F_Content = entity.F_Content.Replace("script","");
  131. HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
  132. //没有文件上传,直接返回
  133. if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName))
  134. {
  135. articleIBLL.SaveEntity(keyValue, entity);
  136. }
  137. else
  138. {
  139. string FileEextension = Path.GetExtension(files[0].FileName);
  140. ImgEntity imgEntity = null;
  141. if (string.IsNullOrEmpty(entity.F_Img))
  142. {
  143. imgEntity = new ImgEntity();
  144. }
  145. else
  146. {
  147. imgEntity = imgIBLL.GetEntity(entity.F_Img);
  148. }
  149. imgEntity.F_Name = files[0].FileName;
  150. imgEntity.F_ExName = FileEextension;
  151. byte[] bytes = new byte[files[0].InputStream.Length];
  152. files[0].InputStream.Read(bytes, 0, bytes.Length);
  153. imgEntity.F_Content = Convert.ToBase64String(bytes);
  154. imgIBLL.SaveEntity(entity.F_Img, imgEntity);
  155. entity.F_ImgName = imgEntity.F_Name;
  156. entity.F_Img = imgEntity.F_Id;
  157. articleIBLL.SaveEntity(keyValue, entity);
  158. }
  159. return Success("保存成功。");
  160. }
  161. #endregion
  162. #region 扩展方法
  163. /// <summary>
  164. /// 获取设置图片
  165. /// </summary>
  166. /// <param name="keyValue">主键</param>
  167. /// <returns></returns>
  168. [HttpGet]
  169. public ActionResult GetImg(string keyValue)
  170. {
  171. articleIBLL.GetImg(keyValue);
  172. return Success("获取成功。");
  173. }
  174. #endregion
  175. }
  176. }