コード例 #1
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (!(context.Controller is IObjectController controller))
            {
                return;
            }

            var resourceType = context.ActionDescriptor is ControllerActionDescriptor descriptor
                ? descriptor.MethodInfo.GetCustomAttribute(typeof(ObjectTypeAttribute)) is ObjectTypeAttribute
                               objectTypeAttribute ? objectTypeAttribute.Type : controller.ObjectType
                : controller.ObjectType;

            var qc = new QueryContext
            {
                Type = resourceType
            };

            var qs = QueryHelpers.ParseQuery(context.HttpContext.Request.QueryString.Value);

            if (context.Result == null)
            {
                PageFilterAttribute.Execute(context, qs, qc);
            }

            if (context.Result == null)
            {
                SortFilterAttribute.Execute(context, qs, qc);
            }

            if (context.Result == null)
            {
                FieldsFilterAttribute.Execute(context, qs, qc);
            }

            if (context.Result == null)
            {
                FilterFilterAttribute.Execute(context, qs, qc);
            }

            if (context.Result == null)
            {
                ProjectionFilterAttribute.Execute(context, qs, qc);
            }
        }
コード例 #2
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var qs = QueryHelpers.ParseQuery(context.HttpContext.Request.QueryString.Value);
            var qc = new QueryContext();

            if (context.ActionArguments.ContainsKey("page"))
            {
                PageFilterAttribute.Execute(context, qs, qc);
            }

            if (context.ActionArguments.ContainsKey("stream"))
            {
                StreamFilterAttribute.Execute(context, qs, qc);
            }

            if (context.ActionArguments.ContainsKey("sort"))
            {
                SortFilterAttribute.Execute(context, qs, qc);
            }

            if (context.ActionArguments.ContainsKey("fields"))
            {
                FieldsFilterAttribute.Execute(context, qs, qc);
            }

            if (context.ActionArguments.ContainsKey("filter"))
            {
                FilterFilterAttribute.Execute(context, qs, qc);
            }

            if (context.ActionArguments.ContainsKey("projection"))
            {
                ProjectionFilterAttribute.Execute(context, qs, qc);
            }

            if (qc.Errors?.Count > 0)
            {
                context.Result = new ErrorResult(new Error(ErrorEvents.ValidationFailed,
                                                           ErrorStrings.ValidationFailed, (HttpStatusCode)422, qc.Errors));
            }
        }