| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Utility.Entity; |
| | | using Utility.Extension; |
| | | |
| | | namespace Utility |
| | | { |
| | |
| | | // 在执行动作之后的逻辑 |
| | | if (resultContext.Result is ObjectResult objectResult) |
| | | { |
| | | var apiResponse = new ApiResponse<object>( |
| | | context.HttpContext.Response.StatusCode, |
| | | context.HttpContext.Response.StatusCode == 200 ? "请求成功" : "错误", |
| | | objectResult.Value); |
| | | |
| | | //if (resultContext.Result is SqlSugarPagedList) |
| | | //{ |
| | | // apiResponse.count = ((SqlSugarPagedList)resultContext.Result).Total; |
| | | //} |
| | | |
| | | ApiResponse<object> apiResponse; |
| | | if (objectResult.Value is SqlSugarPagedList) |
| | | { |
| | | apiResponse = new ApiResponse<object>( |
| | | context.HttpContext.Response.StatusCode == 200 ? 0 : 1, |
| | | context.HttpContext.Response.StatusCode == 200 ? "请求成功" : "错误", |
| | | ((SqlSugarPagedList)objectResult.Value).Items, |
| | | ((SqlSugarPagedList)objectResult.Value).Total); |
| | | } |
| | | else |
| | | { |
| | | apiResponse = new ApiResponse<object>( |
| | | context.HttpContext.Response.StatusCode == 200 ? 0 : 1, |
| | | context.HttpContext.Response.StatusCode == 200 ? "请求成功" : "错误", |
| | | objectResult.Value); |
| | | } |
| | | var json = JsonConvert.SerializeObject(apiResponse); |
| | | context.HttpContext.Response.ContentType = "application/json"; |
| | | context.HttpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(json); |
| | |
| | | if (resultContext.Result is EmptyResult) |
| | | { |
| | | var apiResponse = new ApiResponse<object>( |
| | | context.HttpContext.Response.StatusCode, |
| | | context.HttpContext.Response.StatusCode == 200 ? 0 : 1, |
| | | context.HttpContext.Response.StatusCode == 200 ? "请求成功" : "错误", |
| | | "请求成功" |
| | | ); |