/// <summary> /// Validates the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>The true to continue and false otherwise</returns> public abstract bool Validate(VApiArgs args);
/// <summary> /// Called when validation fails. /// </summary> /// <param name="args">The args.</param> public abstract void OnValidationFailure(VApiArgs args);
/// <summary> /// Called when validation fails. /// </summary> /// <param name="args">The args.</param> public override void OnValidationFailure(VApiArgs args) { args.Response.StatusCode = (int)HttpStatusCode.PreconditionFailed; args.Response.AddHeader("X-Validation", "PreconditionFailed - " + this.QueryStringParameterName); }
/// <summary> /// Validates the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>The true to continue and false otherwise</returns> public override bool Validate(VApiArgs args) { return string.IsNullOrWhiteSpace(args.QueryString[this.QueryStringParameterName]); }
/// <summary> /// Runs the controller. /// </summary> /// <param name="application">The application.</param> /// <param name="controller">The WebAPI controller.</param> private static void RunController(HttpApplication application, VApiController controller) { var context = application.Context; var method = TryResolveHttpMethod(context); if (method.HasValue) { var args = new VApiArgs(context); switch (method.Value) { case VApiHttpMethod.Get: var getcontroller = controller.ActionController as IApiGetActionController; if (getcontroller != null) { /* Set Common headers */ SetBeginRequestGetMethodtHttpResponseHeaders(context, context.Response); string json = getcontroller.Get(args); #if DEBUG /* Disable the compression for JSON Debug Viewers */ ContextOnPreSendRequestContent(application, false, json); #else ContextOnPreSendRequestContent(application, !getcontroller.IsCompressionDisabled, json); #endif } else { SetMethodNotAllowedStatusCode(context, method.Value); } break; case VApiHttpMethod.Post: var postcontroller = controller.ActionController as IApiPostActionController; if (postcontroller != null) { postcontroller.Post(args); } else { SetMethodNotAllowedStatusCode(context, method.Value); } break; case VApiHttpMethod.Put: var putcontroller = controller.ActionController as IApiPutActionController; if (putcontroller != null) { putcontroller.Put(args); } else { SetMethodNotAllowedStatusCode(context, method.Value); } break; case VApiHttpMethod.Delete: var deletecontroller = controller.ActionController as IApiDeleteActionController; if (deletecontroller != null) { deletecontroller.Delete(args); } else { SetMethodNotAllowedStatusCode(context, method.Value); } break; default: SetMethodNotAllowedStatusCode(context, method.Value); // ReSharper disable RedundantJumpStatement break; // ReSharper restore RedundantJumpStatement } } }