/// <summary> /// 返回JSON试图结果。 /// </summary> /// <param name="result">数据结果。</param> /// <param name="args">参数。</param> /// <returns>返回JSON试图结果。</returns> protected IActionResult Json(DataResult result, params object[] args) { if (result.Succeed()) { return(Json(StatusType.Success, result.ToString(args))); } return(Json(StatusType.Danger, result.ToString(args))); }
/// <summary> /// 返回带状态消息页面结果。 /// </summary> /// <param name="result">数据结果。</param> /// <param name="args">参数。</param> /// <returns>返回当前页面结果。</returns> protected IActionResult RedirectToResult(DataResult result, params object[] args) { if (result.Succeed()) { return(RedirectToPage(StatusType.Success, result.ToString(args))); } return(RedirectToPage(StatusType.Danger, result.ToString(args))); }
/// <summary> /// 显示消息。 /// </summary> /// <param name="result">操作接口。</param> /// <param name="url">转向地址。</param> /// <param name="model">模型实例对象。</param> /// <param name="args">参数。</param> protected IActionResult View(DataResult result, string url, object model, params object[] args) { if (result.Succeed()) { return(View(StatusType.Success, result.ToString(args), model, url)); } return(View(StatusType.Danger, result.ToString(args), model)); }
/// <summary> /// 返回带状态消息页面结果。 /// </summary> /// <param name="result">数据结果。</param> /// <param name="args">参数。</param> /// <returns>返回当前页面结果。</returns> protected IActionResult Page(DataResult result, params object[] args) { var message = result.ToString(args); if (result) { return(SuccessPage(message)); } return(ErrorPage(message)); }
/// <summary> /// 返回数据操作结果,如果成功则返回成功实例,并且保存到日志中。 /// </summary> /// <param name="result">数据操作结果。</param> /// <param name="name">名称。</param> /// <returns>返回数据操作结果。</returns> protected virtual async Task <IActionResult> JsonAsync(DataResult result, string name) { var api = new ApiResult { Message = result.ToString(name), Code = result ? 0 : result.Code }; if (result) { await LogAsync(api.Message); } return(Json(api)); }
/// <summary> /// 返回数据操作结果,如果成功则返回成功实例。 /// </summary> /// <param name="result">数据操作结果。</param> /// <param name="name">名称。</param> /// <param name="logged">如果操作成功,是否保存到日志记录中。</param> /// <returns>返回数据操作结果。</returns> protected virtual IActionResult Json(DataResult result, string name, bool logged = false) { var api = new ApiResult { Message = result.ToString(name), Code = result ? 0 : result.Code }; if (result) { Log(api.Message); } return(Json(api)); }
/// <summary> /// 添加事件日志。 /// </summary> /// <param name="result">数据操作结果。</param> /// <param name="name">名称。</param> /// <param name="eventType">事件类型名称。</param> /// <param name="source">来源。</param> public virtual async Task LogResultAsync(DataResult result, string name, string eventType = null, string source = null) { if (!result) { return; } await LogAsync(@event => { @event.Message = result.ToString(name); @event.Source = source; @event.Level = EventLevel.Success; }, eventType); }
/// <summary> /// 添加事件日志。 /// </summary> /// <param name="result">数据操作结果。</param> /// <param name="name">名称。</param> /// <param name="eventType">事件类型名称。</param> /// <param name="source">来源。</param> public virtual void LogResult(DataResult result, string name, string eventType = null, string source = null) { if (!result) { return; } Log(@event => { @event.Message = result.ToString(name); @event.Source = source; @event.Level = EventLevel.Success; }, eventType); }