using Learun.Loger; using Learun.Util; using Learun.Util.Operat; using System.Web.Mvc; namespace Learun.Application.Web { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.08 /// 描 述:基础控制器 /// [HandlerLogin(FilterMode.Enforce)] public abstract class MvcControllerBase : Controller { #region 日志操作 /// /// 日志对象实体 /// private Log _logger; /// /// 日志操作 /// public Log Logger { get { return _logger ?? (_logger = LogFactory.GetLogger(this.GetType().ToString())); } } #endregion #region 请求响应 /// /// 返回成功消息 /// /// 数据 /// protected virtual ActionResult ToJsonResult(object data) { return Content(data.ToJson()); } /// /// 返回成功消息 /// /// 消息 /// protected virtual ActionResult Success(string info) { return Content(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson()); } protected virtual ActionResult Success(object data) { return Content(new ResParameter { code = ResponseCode.success, info ="响应成功", data = data }.ToJson()); } /// /// 返回成功消息 /// /// 数据 /// protected virtual ActionResult SuccessString(string data) { return Content(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson()); } /// /// 返回成功数据 /// /// 数据 /// protected virtual ActionResult JsonResult(object data) { return Content(new ResParameter { code = ResponseCode.success, info = "响应成功", data = data }.ToJson()); } /// /// 返回成功消息 /// /// 消息 /// 数据 /// protected virtual ActionResult Success(string info, object data) { return Content(new ResParameter { code = ResponseCode.success, info = info, data = data }.ToJson()); } /// /// 带操作日志 /// /// /// protected virtual ActionResult Success(string info, string title, OperationType type, string keyValue, string content) { OperateLogModel operateLogModel = new OperateLogModel(); operateLogModel.title = title; operateLogModel.type = type; operateLogModel.url = (string)WebHelper.GetHttpItems("currentUrl"); operateLogModel.sourceObjectId = keyValue; operateLogModel.sourceContentJson = content; OperatorHelper.Instance.WriteOperateLog(operateLogModel); return Content(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson()); } /// /// 返回失败消息 /// /// 消息 /// protected virtual ActionResult Fail(string info) { return Content(new ResParameter { code = ResponseCode.fail, info = info }.ToJson()); } /// /// 返回失败消息 /// /// 消息 /// 消息 /// protected virtual ActionResult Fail(string info, object data) { return Content(new ResParameter { code = ResponseCode.fail, info = info, data = data }.ToJson()); } #endregion } }