You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
877 B
30 lines
877 B
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using QYMessageCenter.Common.Models;
|
|
|
|
namespace QYMessageCenter.Filters
|
|
{
|
|
public class ResultFilter : IResultFilter
|
|
{
|
|
public void OnResultExecuted(ResultExecutedContext context)
|
|
{
|
|
|
|
}
|
|
|
|
public void OnResultExecuting(ResultExecutingContext context)
|
|
{
|
|
if (context.Result is ObjectResult)
|
|
{
|
|
var objectResult = context.Result as ObjectResult;
|
|
if (!(objectResult.Value is ApiResponse))
|
|
{
|
|
objectResult.Value = new ApiResponse() { Data = objectResult.Value };
|
|
}
|
|
}
|
|
else if (context.Result is EmptyResult)
|
|
{
|
|
context.Result = new ObjectResult(new ApiResponse());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|