/// <summary> /// 操作结果转ajax操作结果 /// </summary> public static AjaxResult ToAjaxResult(this OperationResult <object> result) { string content = result.Message ?? result.ResultType.ToDescription(); AjaxResultType type = result.ResultType.ToAjaxResultType(); return(new AjaxResult(content, type)); }
public async Task <ActionResult> Delete([ModelBinder(typeof(JsonBinder <int>))] List <int> ids) { ids.CheckNotNull("ids"); OperationResult result = new OperationResult(OperationResultType.Success); List <string> names = new List <string>(); foreach (int id in ids) { result = await _demoContract.DeleteDemoEntityAsync(id); if (result.ResultType.IsError()) { break; } names.Add(result.Data.ToString()); } string msg = result.Message ?? result.ResultType.ToDescription(); AjaxResultType msgType = result.ResultType.ToAjaxResultType(); if (msgType != AjaxResultType.Error) { msg = "示例实体“{0}”删除成功。".FormatWith(names.ExpandAndToString()); } return(Json(new AjaxResult(msg, msgType))); }
public AjaxResult(AjaxResultType resultType = AjaxResultType.Success, string message = "", string redirectUrl = @"/", object paramData = null) : base() { this.Data = new AjaxResultData() { result = resultType, message = message, redirectUrl = string.Concat(redirectUrl, convertParamsToString(paramData)) }; }
public AjaxResult(string message, bool success, object data, AjaxResultType type) { this.Message = message; this.Data = data; this.Type = type; this.Success = success; }
public AjaxResult(string message, object data, AjaxResultType type) { this.Message = message; this.Data = data; this.Type = type; this.Success = Succeeded(); }
/// <summary> /// 初始化一个<see cref="AjaxResult{TResult}"/>类型的新实例 /// </summary> public AjaxResult(string content, AjaxResultType ajaxResultType = AjaxResultType.Success, bool unAuthorizedRequest = false) { ResultType = ajaxResultType; Success = ResultType == AjaxResultType.Success; Content = content; UnAuthorizedRequest = unAuthorizedRequest; }
public async Task <ActionResult> Update([ModelBinder(typeof(JsonBinder <DemoEntityDto>))] List <DemoEntityDto> models) { models.CheckNotNull("models"); OperationResult result = new OperationResult(OperationResultType.Success); List <string> names = new List <string>(); foreach (DemoEntityDto dto in models) { result = await _demoContract.UpdateDemoEntityAsync(dto); if (result.ResultType.IsError()) { break; } names.Add(dto.Name); } string msg = result.Message ?? result.ResultType.ToDescription(); AjaxResultType msgType = result.ResultType.ToAjaxResultType(); if (msgType != AjaxResultType.Error) { msg = "示例实体“{0}”更新成功。".FormatWith(names.ExpandAndToString()); } return(Json(new AjaxResult(msg, msgType))); }
/// <summary> /// 将业务操作结果转ajax操作结果,可确定是否包含Data /// </summary> /// <param name="result">业务操作结果</param> /// <param name="containsData">是否包含Data,默认不包含</param> /// <returns></returns> public static AjaxResult ToAjaxResult(this OperationResult result, bool containsData = false) { string content = result.Message ?? result.ResultType.ToDescription(); AjaxResultType type = result.ResultType.ToAjaxResultType(); return(containsData ? new AjaxResult(content, type, result.Data) : new AjaxResult(content, type)); }
/// <summary> /// 将业务操作结果转ajax操作结果,并处理强类型的 <see cref="OperationResult.Data"/> /// </summary> public static AjaxResult ToAjaxResult <T>(this OperationResult <T> result, Func <T, object> dataFunc = null) { string content = result.Message ?? result.ResultType.ToDescription(); AjaxResultType type = result.ResultType.ToAjaxResultType(); object data = dataFunc == null ? result.Data : dataFunc(result.Data); return(new AjaxResult(content, type, data)); }
/// <summary> /// 创建Ajax响应 /// </summary> /// <param name="context">HttpContext</param> /// <param name="data">返回数据</param> /// <param name="type">Ajax操作结果类型</param> /// <param name="content">消息内容</param> /// 时间:2016/10/26 10:15 /// 备注: public static void CreateResponse <T>(this HttpContext context, T data, AjaxResultType type, string content) { AjaxResult <T> _jsonResult = new AjaxResult <T>(content, data, type); string _jsonString = SerializeHelper.JsonSerialize <AjaxResult <T> >(_jsonResult); context.Response.Write(_jsonString); context.ApplicationInstance.CompleteRequest(); }
/// <summary> /// Ajax请求结果 /// </summary> /// <param name="state">请求状态</param> /// <param name="message">附加信息</param> /// <param name="data">需要返回的数据</param> /// <returns></returns> public static AjaxResult Result(AjaxResultType state, string message, object data) { AjaxResult result = new AjaxResult(); result.State = state; result.Message = message; result.Data = data; return(result); }
public static AjaxResult ToAjaxResult <T>(this OperationResponse <T> operationResult) { var message = operationResult.Message ?? operationResult.Type.ToDescription(); AjaxResultType type = operationResult.Type.ToAjaxResultType(); return(new AjaxResult(message, type, operationResult.Data) { Success = operationResult.Success }); }
public static async Task <AjaxResult> ToAjaxResult(this Task <OperationResponse> operationResponse) { var result = await operationResponse; var message = result.Message ?? result.Type.ToDescription(); AjaxResultType type = result.Type.ToAjaxResultType(); return(new AjaxResult(message, type, result.Data) { Success = result.Success }); }
/// <summary> /// 将业务操作结果转ajax操作结果,会将 object 类型的 <see cref="OperationResult.Data"/> 转换为强类型 T,再通过 dataFunc 进行进一步处理 /// </summary> public static AjaxResult ToAjaxResult <T>(this OperationResult result, Func <T, object> dataFunc) { string content = result.Message ?? result.ResultType.ToDescription(); AjaxResultType type = result.ResultType.ToAjaxResultType(); object data = null; if (result.Data != null) { if (dataFunc != null && result.Data is T resultData) { data = dataFunc(resultData); } } return(new AjaxResult(content, type, data)); }
/// <summary> /// 构造函数 /// </summary> /// <param name="content">消息内容</param> /// <param name="type">Ajax操作结果类型</param> /// <param name="data">返回数据</param> public AjaxResult(string content, AjaxResultType type, object data) : this(content, data, type) { }
/// <summary> /// 初始化一个<see cref="AjaxResult"/>类型的新实例 /// </summary> public AjaxResult(string content, object data, AjaxResultType type = AjaxResultType.Info) { Type = type; Content = content; Data = data; }
/// <summary> /// 初始化一个<see cref="AjaxResult"/>类型的新实例 /// </summary> public AjaxResult(string content, AjaxResultType type = AjaxResultType.Info, object data = null) : this(content, data, type) { }
/// <summary> /// Called after the action executes, before the action result. /// </summary> /// <param name="context">The <see cref="T:Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext" />.</param> public void OnActionExecuted(ActionExecutedContext context) { ScopedDictionary dict = context.HttpContext.RequestServices.GetService <ScopedDictionary>(); AjaxResultType type = AjaxResultType.Success; string message = null; if (context.Exception != null && !context.ExceptionHandled) { Exception ex = context.Exception; _logger.LogError(new EventId(), ex, ex.Message); message = ex.Message; if (context.HttpContext.Request.IsAjaxRequest() || context.HttpContext.Request.IsJsonContextType()) { if (!context.HttpContext.Response.HasStarted) { context.Result = new JsonResult(new AjaxResult(ex.Message, AjaxResultType.Error)); } context.ExceptionHandled = true; } } if (context.Result is JsonResult result1) { if (result1.Value is AjaxResult ajax) { type = ajax.Type; message = ajax.Content; if (ajax.Succeeded()) { _unitOfWork?.Commit(); } } } else if (context.Result is ObjectResult result2) { if (result2.Value is AjaxResult ajax) { type = ajax.Type; message = ajax.Content; if (ajax.Succeeded()) { _unitOfWork?.Commit(); } } else { _unitOfWork?.Commit(); } } //普通请求 else if (context.HttpContext.Response.StatusCode >= 400) { switch (context.HttpContext.Response.StatusCode) { case 401: type = AjaxResultType.UnAuth; break; case 403: type = AjaxResultType.UnAuth; break; case 404: type = AjaxResultType.UnAuth; break; case 423: type = AjaxResultType.UnAuth; break; default: type = AjaxResultType.Error; break; } } else { type = AjaxResultType.Success; _unitOfWork?.Commit(); } if (dict.AuditOperation != null) { dict.AuditOperation.ResultType = type; dict.AuditOperation.Message = message; } }
public FtpAjaxResult(AjaxResultType code, string msg) { this.code = code; this.errormessage = msg; }
/// <summary> /// 重写方法,实现事务自动提交功能 /// </summary> /// <param name="context"></param> public override void OnResultExecuted(ResultExecutedContext context) { ScopedDictionary dict = context.HttpContext.RequestServices.GetService <ScopedDictionary>(); AjaxResultType type = AjaxResultType.Success; string message = null; if (context.Result is JsonResult result1) { if (result1.Value is AjaxResult ajax) { type = ajax.Type; message = ajax.Content; if (ajax.Successed()) { _unitOfWorkManager?.Commit(); } } } else if (context.Result is ObjectResult result2) { if (result2.Value is AjaxResult ajax) { type = ajax.Type; message = ajax.Content; if (ajax.Successed()) { _unitOfWorkManager?.Commit(); } } _unitOfWorkManager?.Commit(); } //普通请求 else if (context.HttpContext.Response.StatusCode >= 400) { switch (context.HttpContext.Response.StatusCode) { case 401: type = AjaxResultType.UnAuth; break; case 403: type = AjaxResultType.UnAuth; break; case 404: type = AjaxResultType.UnAuth; break; case 423: type = AjaxResultType.UnAuth; break; default: type = AjaxResultType.Error; break; } } else { type = AjaxResultType.Success; _unitOfWorkManager?.Commit(); } if (dict.AuditOperation != null) { dict.AuditOperation.ResultType = type; dict.AuditOperation.Message = message; } }
/// <summary> /// 构造函数 /// </summary> /// <param name="content">消息内容</param> /// <param name="data">返回数据</param> /// <param name="type">Ajax操作结果类型</param> public AjaxResult(string content, object data, AjaxResultType type) { Type = type.ToString(); Content = content; Data = data; }
/// <summary> /// Ajax请求结果 /// </summary> /// <param name="state">请求状态</param> /// <param name="message">附加信息</param> /// <returns></returns> public static AjaxResult Result(AjaxResultType state, string message) { return(Result(state, message, null)); }
public AjaxResult(AjaxResultType type = AjaxResultType.Success, object data = null) : this("", data, type) { }
/// <summary> /// Ajax请求结果 /// </summary> /// <param name="state">请求状态</param> /// <param name="data">需要返回的数据</param> /// <returns></returns> public static AjaxResult Result(AjaxResultType state, object data) { return(Result(AjaxResultType.success, string.Empty, data)); }
private static Task HandleWebApiExceptionAsync(HttpContext context, int statusCode, string msg, AjaxResultType resultType) { context.Response.Clear(); context.Response.StatusCode = statusCode; context.Response.ContentType = "application/json; charset=utf-8"; return(context.Response.WriteAsync(new AjaxResult(content: msg, ajaxResultType: resultType, unAuthorizedRequest: statusCode.Equals(401)).ToJsonString())); }
public AjaxResult(string message, AjaxResultType type = AjaxResultType.Success, object data = null) { this.Message = message; this.Data = data; this.Type = type; }
public AjaxResult(AjaxResultType type = AjaxResultType.Success) : this("", null, type) { }
/// <summary> /// 初始化一个<see cref="AjaxResult"/>类型的新实例 /// </summary> public AjaxResult(string content, object data, AjaxResultType type = AjaxResultType.Info) { Type = type.ToString(); Content = content; Data = data; }
public AjaxResult(string message, AjaxResultType type = AjaxResultType.Success, object data = null) : this(message, data, type) { }
/// <summary> /// 初始化一个<see cref="AjaxResult"/>类型的新实例 /// </summary> public AjaxResult(string message, object data, AjaxResultType type = AjaxResultType.Success) { Status = type.ToString(); Message = message; Data = data; }
/// <summary> /// 构造函数 /// </summary> /// <param name="message">消息内容</param> /// <param name="data">返回数据</param> /// <param name="resultType">Ajax操作结果类型</param> public AjaxResult(string message, T data, AjaxResultType resultType) : base(message, data) { ResultType = resultType; }