update 解决dapper结果无法转为小写的问题

This commit is contained in:
2021-05-20 15:26:28 +08:00
parent 6cbb663e97
commit 4ec43c220e
3 changed files with 43 additions and 31 deletions

View File

@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Ewide.Core
{
@@ -17,6 +18,19 @@ namespace Ewide.Core
[SkipScan, UnifyModel(typeof(XnRestfulResult<>))]
public class XnRestfulResultProvider : IUnifyResultProvider
{
private IActionResult DisplayJson(object data)
{
return new ContentResult
{
Content = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(),
DateFormatString = "yyyy-MM-dd HH:mm:ss"
}),
ContentType = "application/json"
};
}
/// <summary>
/// 异常返回值
/// </summary>
@@ -27,7 +41,7 @@ namespace Ewide.Core
// 解析异常信息
var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context);
return new JsonResult(new XnRestfulResult<object>
return DisplayJson(new XnRestfulResult<object>
{
Code = StatusCode,
Success = false,
@@ -93,7 +107,7 @@ namespace Ewide.Core
else if (context.Result is EmptyResult) data = null;
else return null;
return new JsonResult(new XnRestfulResult<object>
return DisplayJson(new XnRestfulResult<object>
{
Code = context.Result is EmptyResult ? StatusCodes.Status204NoContent : StatusCodes.Status200OK, // 处理没有返回值情况 204
Success = true,
@@ -114,7 +128,7 @@ namespace Ewide.Core
/// <returns></returns>
public IActionResult OnValidateFailed(ActionExecutingContext context, ModelStateDictionary modelStates, IEnumerable<ValidateFailedModel> validationResults, string validateFailedMessage)
{
return new JsonResult(new XnRestfulResult<object>
return DisplayJson(new XnRestfulResult<object>
{
Code = StatusCodes.Status400BadRequest,
Success = false,