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.

MvcControllerBase.cs 4.3 KiB

4 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Learun.Loger;
  2. using Learun.Util;
  3. using Learun.Util.Operat;
  4. using System.Web.Mvc;
  5. namespace Learun.Application.Web
  6. {
  7. /// <summary>
  8. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  9. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  10. /// 创建人:陈彬彬
  11. /// 日 期:2017.03.08
  12. /// 描 述:基础控制器
  13. /// </summary>
  14. [HandlerLogin(FilterMode.Enforce)]
  15. public abstract class MvcControllerBase : Controller
  16. {
  17. #region 日志操作
  18. /// <summary>
  19. /// 日志对象实体
  20. /// </summary>
  21. private Log _logger;
  22. /// <summary>
  23. /// 日志操作
  24. /// </summary>
  25. public Log Logger
  26. {
  27. get { return _logger ?? (_logger = LogFactory.GetLogger(this.GetType().ToString())); }
  28. }
  29. #endregion
  30. #region 请求响应
  31. /// <summary>
  32. /// 返回成功消息
  33. /// </summary>
  34. /// <param name="data">数据</param>
  35. /// <returns></returns>
  36. protected virtual ActionResult ToJsonResult(object data)
  37. {
  38. return Content(data.ToJson());
  39. }
  40. /// <summary>
  41. /// 返回成功消息
  42. /// </summary>
  43. /// <param name="info">消息</param>
  44. /// <returns></returns>
  45. protected virtual ActionResult Success(string info)
  46. {
  47. return Content(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson());
  48. }
  49. protected virtual ActionResult Success(object data)
  50. {
  51. return Content(new ResParameter { code = ResponseCode.success, info ="响应成功", data = data }.ToJson());
  52. }
  53. /// <summary>
  54. /// 返回成功消息
  55. /// </summary>
  56. /// <param name="data">数据</param>
  57. /// <returns></returns>
  58. protected virtual ActionResult SuccessString(string data)
  59. {
  60. return Content(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson());
  61. }
  62. /// <summary>
  63. /// 返回成功数据
  64. /// </summary>
  65. /// <param name="data">数据</param>
  66. /// <returns></returns>
  67. protected virtual ActionResult JsonResult(object data)
  68. {
  69. return Content(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson());
  70. }
  71. /// <summary>
  72. /// 返回成功消息
  73. /// </summary>
  74. /// <param name="info">消息</param>
  75. /// <param name="data">数据</param>
  76. /// <returns></returns>
  77. protected virtual ActionResult Success(string info, object data)
  78. {
  79. return Content(new ResParameter { code = ResponseCode.success, info = info, data = data }.ToJson());
  80. }
  81. /// <summary>
  82. /// 带操作日志
  83. /// </summary>
  84. /// <param name="info"></param>
  85. /// <returns></returns>
  86. protected virtual ActionResult Success(string info, string title, OperationType type, string keyValue, string content)
  87. {
  88. OperateLogModel operateLogModel = new OperateLogModel();
  89. operateLogModel.title = title;
  90. operateLogModel.type = type;
  91. operateLogModel.url = (string)WebHelper.GetHttpItems("currentUrl");
  92. operateLogModel.sourceObjectId = keyValue;
  93. operateLogModel.sourceContentJson = content;
  94. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  95. return Content(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson());
  96. }
  97. /// <summary>
  98. /// 返回失败消息
  99. /// </summary>
  100. /// <param name="info">消息</param>
  101. /// <returns></returns>
  102. protected virtual ActionResult Fail(string info)
  103. {
  104. return Content(new ResParameter { code = ResponseCode.fail, info = info }.ToJson());
  105. }
  106. /// <summary>
  107. /// 返回失败消息
  108. /// </summary>
  109. /// <param name="info">消息</param>
  110. /// <param name="data">消息</param>
  111. /// <returns></returns>
  112. protected virtual ActionResult Fail(string info, object data)
  113. {
  114. return Content(new ResParameter { code = ResponseCode.fail, info = info, data = data }.ToJson());
  115. }
  116. #endregion
  117. }
  118. }