using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Core.Attributes;
|
|
namespace WIDESEA_Core.Utilities
|
{
|
public static class ParamsValidator
|
{
|
public static void ActionParamsValidator(this ActionExecutingContext context)
|
{
|
List<object> obj = context.ActionDescriptor.EndpointMetadata.ToList();
|
|
if (obj.Any(x => x is MethodParamsValidateAttribute))
|
{
|
foreach (var param in context.ActionDescriptor.Parameters)
|
{
|
ModelValidateAttribute? modelValidate = param.ParameterType.GetCustomAttribute<ModelValidateAttribute>();
|
if (modelValidate != null && context.ActionArguments.TryGetValue(param.Name, out object? value) && value != null)
|
{
|
(bool, string, object?) result = ModelValidate.ValidateModelData(value, param.ParameterType);
|
if (!result.Item1)
|
{
|
context.Result = new JsonResult(new WebResponseContent()
|
{
|
Status = false,
|
Data = result.Item3,
|
Message = result.Item2
|
});
|
}
|
}
|
//else
|
//{
|
// if (param.ParameterType == typeof(SaveModel) && context.ActionArguments.TryGetValue(param.Name, out value) && value != null)
|
// {
|
|
// }
|
//}
|
}
|
}
|
}
|
}
|
}
|