Exemplo n.º 1
0
        /// <summary>
        /// <para>Gather required parameters of database stored procedure/function from body and from uri query string.</para>
        /// <para>1. From body is the first priority, the input parameters will only be gathered from body if the request has a message body;</para>
        /// <para>2. Suppose all required input parameters were encapsulated as a JSON string into a special query string named "JsonInput";</para>
        /// <para>3. Any query string which name matched with stored procedure input parameter' name will be forwarded to database.</para>
        /// <para>See example at https://github.com/DataBooster/DbWebApi/blob/master/Server/Sample/MyDbWebApi/Controllers/DbWebApiController.cs </para>
        /// </summary>
        /// <param name="parametersFromBody">Auto-binded InputParameters from the request body.</param>
        /// <param name="request">The HTTP request.</param>
        public static InputParameters SupplementFromQueryString(InputParameters parametersFromBody, HttpRequestMessage request)
        {
            if (parametersFromBody == null)
            {
                return(new InputParameters(request.GatherInputParameters(null)));
            }

            if (parametersFromBody.ForBulkExecuting)
            {
                request.BulkGatherInputParameters(parametersFromBody.BulkParameters);
            }
            else
            if (parametersFromBody.Parameters == null)
            {
                parametersFromBody.Parameters = request.GatherInputParameters(null);
            }
            else
            {
                request.GatherInputParameters(parametersFromBody.Parameters);
            }

            return(parametersFromBody);
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>The main DbWebApi extension method to ApiController.</para>
        /// <para>This method combines ExecuteDbApi and BulkExecuteDbApi together,</para>
        /// <para>Its actual behavior determined by the InputParameters(from request body) dynamically.</para>
        /// <para>See example at https://github.com/DataBooster/DbWebApi/blob/master/Server/Sample/MyDbWebApi/Controllers/DbWebApiController.cs </para>
        /// </summary>
        /// <param name="apiController">Your ApiController to invoke this extension method</param>
        /// <param name="sp">Specifies the fully qualified name of database stored procedure or function</param>
        /// <param name="dynParameters">The InputParameters auto-binding from the request body</param>
        /// <returns>A complete HttpResponseMessage contains result data returned by the database</returns>
        public static HttpResponseMessage DynExecuteDbApi(this ApiController apiController, string sp, InputParameters dynParameters)
        {
            if (dynParameters == null)
            {
                return(apiController.ExecuteDbApi(sp, null));
            }

            if (dynParameters.ForBulkExecuting)
            {
                return(apiController.BulkExecuteDbApi(sp, dynParameters.BulkParameters));
            }
            else
            {
                return(apiController.ExecuteDbApi(sp, dynParameters.Parameters));
            }
        }