|
|
@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ds.WMS.WebCore
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public static class ActionResultHelper
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 统一返回数据结果
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
|
|
public static ActionExecutedContext ActionForResult(ActionExecutedContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var response = new DataResult
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Data = (context.Result as ObjectResult)?.Value,
|
|
|
|
|
|
|
|
Code = ResultCode.Success,
|
|
|
|
|
|
|
|
Message = "操作成功"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context.Result is ForbidResult)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
response = new DataResult
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Data = (context.Result as ObjectResult)?.Value,
|
|
|
|
|
|
|
|
Code = ResultCode.NoPermission,
|
|
|
|
|
|
|
|
Message = "没有权限"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (context.Result is NotFoundResult)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
response = new DataResult
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Data = (context.Result as ObjectResult)?.Value,
|
|
|
|
|
|
|
|
Code = ResultCode.NoDatavailable,
|
|
|
|
|
|
|
|
Message = "没有数据"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (context.Result is BadRequestResult)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
response = new DataResult
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Data = (context.Result as ObjectResult)?.Value,
|
|
|
|
|
|
|
|
Code = ResultCode.Fail,
|
|
|
|
|
|
|
|
Message = "操作失败"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Result = new ObjectResult(response);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return context;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|