MvcControllerBase.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Reflection;
  3. using Lottomat.Application.Code;
  4. using Lottomat.Util;
  5. using Lottomat.Util.Log;
  6. using Lottomat.Util.WebControl;
  7. using System.Web.Mvc;
  8. using Lottomat.Util.Extension;
  9. using WebGrease;
  10. namespace Lottomat.Application.Admin
  11. {
  12. /// <summary>
  13. /// 版 本 1.0
  14. /// Copyright (c) 2016-2017
  15. /// 创建人:赵轶
  16. /// 日 期:2015.11.9 10:45
  17. /// 描 述:控制器基类
  18. /// </summary>
  19. [HandlerLogin(LoginMode.Enforce)]
  20. public abstract class MvcControllerBase : Controller, ILogger
  21. {
  22. #region 系统日志
  23. /// <summary>
  24. /// 系统日志 主动调用
  25. /// </summary>
  26. private readonly LogHelper _logHelper = new LogHelper(MethodBase.GetCurrentMethod().DeclaringType);
  27. /// <summary>
  28. /// 系统日志 对try块进行了封装
  29. /// </summary>
  30. /// <param name="type"></param>
  31. /// <param name="function">方法名称</param>
  32. /// <param name="errorHandel">异常处理方式</param>
  33. /// <param name="tryHandel">调试代码</param>
  34. /// <param name="catchHandel">异常处理方式</param>
  35. /// <param name="finallHandel">最终处理方式</param>
  36. public void Logger(Type type, string argJsonString, string function, Action tryHandel, Action<Exception> catchHandel = null,
  37. Action finallHandel = null, ErrorHandel errorHandel = ErrorHandel.Throw)
  38. {
  39. LogHelper.Logger(type, argJsonString, function, errorHandel, tryHandel, catchHandel, finallHandel);
  40. }
  41. #endregion
  42. /// <summary>
  43. /// 返回成功消息
  44. /// </summary>
  45. /// <param name="data">数据</param>
  46. /// <returns></returns>
  47. protected virtual ActionResult ToJsonResult(object data)
  48. {
  49. return Content(data.ToJson());
  50. }
  51. /// <summary>
  52. /// 返回成功消息
  53. /// </summary>
  54. /// <param name="message">消息</param>
  55. /// <returns></returns>
  56. protected virtual ActionResult Success(string message)
  57. {
  58. return Content(new AjaxResult<string> { type = ResultType.Success, message = message }.ToJson());
  59. }
  60. /// <summary>
  61. /// 返回成功消息
  62. /// </summary>
  63. /// <param name="message">消息</param>
  64. /// <param name="data">数据</param>
  65. /// <returns></returns>
  66. protected virtual ActionResult Success<T>(string message, T data)
  67. {
  68. return Content(new AjaxResult<T> { type = ResultType.Success, message = message, resultdata = data }.ToJson());
  69. }
  70. /// <summary>
  71. /// 返回失败消息
  72. /// </summary>
  73. /// <param name="message">消息</param>
  74. /// <returns></returns>
  75. protected virtual ActionResult Error(string message)
  76. {
  77. return Content(new AjaxResult<string> { type = ResultType.Error, message = message }.ToJson());
  78. }
  79. }
  80. }