Beispiel #1
0
        public ActionResult <Boolean> Patch([FromRoute] Guid packageId, [FromRoute] String objectType)
        {
            // Do the authentication process with the given request and helpers
            // to determine the result
            ApiAuthenticationResult authResult =
                WebAuthHelper.AuthenticateApiRequest(
                    packageId,
                    objectType,
                    SessionHandler.PackageRepository,
                    Request
                    );

            // Everything work ok? Then continue to the important bits
            if (authResult.StatusCode != HttpStatusCode.OK)
            {
                return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription));
            }

            // Get the body of the request from the stream
            String body = HttpRequestHelper.GetBody(Request);

            if (body == String.Empty)
            {
                return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no data"));
            }

            // Got to the end so must be ok
            return(StatusCode((Int32)HttpStatusCode.OK, ""));
        }
Beispiel #2
0
        public ActionResult <Boolean> Get([FromRoute] Guid packageId, [FromRoute] String objectType)
        {
            // Do the authentication process with the given request and helpers
            // to determine the result
            ApiAuthenticationResult authResult =
                WebAuthHelper.AuthenticateApiRequest(
                    packageId,
                    objectType,
                    SessionHandler.PackageRepository,
                    Request
                    );

            // Everything work ok? Then continue to the important bits
            if (authResult.StatusCode == HttpStatusCode.OK)
            {
                // Use the api definition to get the data connection and
                // definition from the package and then try to connect
                IDataProvider provider = providerFactory.Get(
                    authResult.Package,
                    authResult.Package.DataConnection(authResult.ApiDefinition.DataConnection),
                    authResult.Package.DataDefinition(authResult.ApiDefinition.DataDefinition),
                    true);

                // Are we connected?
                if (provider.Connected)
                {
                    // Return the data with the appropriate filter
                    DataTable results = provider.Read(authResult.Permissions.Filter);

                    // Manage any aliases for the results table
                    ManagedApiHelper.HandleAliases(results, authResult.ApiDefinition.Aliases);

                    // Format the data table as Json
                    return(ManagedApiHelper.ToJson(results));
                }
                else
                {
                    return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not connect to the data source"));
                }
            }
            else
            {
                return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription));
            }
        }
Beispiel #3
0
        public ActionResult <Boolean> Delete([FromRoute] Guid packageId, [FromRoute] String objectType)
        {
            // Do the authentication process with the given request and helpers
            // to determine the result
            ApiAuthenticationResult authResult =
                WebAuthHelper.AuthenticateApiRequest(
                    packageId,
                    objectType,
                    SessionHandler.PackageRepository,
                    Request
                    );

            // Everything work ok? Then continue to the important bits
            if (authResult.StatusCode == HttpStatusCode.OK)
            {
                return(StatusCode((Int32)HttpStatusCode.OK, ""));
            }
            else
            {
                return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription));
            }
        }
Beispiel #4
0
        public ActionResult <Boolean> Post([FromRoute] Guid packageId, [FromRoute] String objectType)
        {
            // Do the authentication process with the given request and helpers
            // to determine the result
            ApiAuthenticationResult authResult =
                WebAuthHelper.AuthenticateApiRequest(
                    packageId,
                    objectType,
                    SessionHandler.PackageRepository,
                    Request
                    );

            // Everything work ok? Then continue to the important bits
            if (authResult.StatusCode != HttpStatusCode.OK)
            {
                return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription));
            }

            // Get the body of the request from the stream
            String body = HttpRequestHelper.GetBody(Request);

            if (body == String.Empty)
            {
                return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no data"));
            }

            // Translate the body
            try
            {
                DataTable data = null;

                // Parse the body to a queryable Json Object (bad formatting will fail it)
                data = ManagedApiHelper.ToDataTable(
                    Request.ContentType.Trim().ToLower(),
                    body,
                    authResult.ApiDefinition,
                    authResult.DataDefinition);

                // Did we get some data from the conversion (depending on the type format)
                if (data != null)
                {
                    // Use the api definition to get the data connection and
                    // definition from the package and then try to connect
                    IDataProvider provider = providerFactory.Get(
                        authResult.Package,
                        authResult.Package.DataConnection(authResult.ApiDefinition.DataConnection),
                        authResult.Package.DataDefinition(authResult.ApiDefinition.DataDefinition),
                        true);

                    // Are we connected?
                    if (provider.Connected)
                    {
                        // Return the data with the appropriate filter
                        // DataTable results = provider.Read(authResult.Permissions.Filter);
                        if (provider.Write(data, ""))
                        {
                        }
                        else
                        {
                            return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not write the data"));
                        }
                    }
                    else
                    {
                        return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not connect to the data source"));
                    }
                }
                else
                {
                    return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no valid data or the format was incorrect"));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((Int32)HttpStatusCode.BadRequest, $"Malformed body content in request ({ex.Message})"));
            }

            // Got to the end so must be ok
            return(StatusCode((Int32)HttpStatusCode.OK, ""));
        }