Esempio n. 1
0
        public async Task <IActionResult> DeleteResource()
        {
            Parameters parameters =
                _parametersProcessorService.ProcessParameters(Request.RouteValues, Request.QueryString);
            string?query = _sparqlFactoryService.GetFinalDeleteQueryForResource(parameters);

            if (query != null)
            {
                bool successful = await _endpointService.ExecuteUpdateSparqlQueryAsync(
                    parameters.RouteParameters.Endpoint,
                    parameters.RouteParameters.Graph, query);

                if (successful)
                {
                    return(NoContent());
                }
            }

            return(BadRequest(new CustomErrorVm()
            {
                CustomErrorMessage =
                    $"Resource could not have been deleted! Check endpoint configuration at {UrlHelperClass.GetEndpointUrl(Request.GetEncodedUrl())}.",
                GeneratedQuery = query
            }));
        }
        public async Task <IActionResult> PutResource([FromBody] ResourceVm resourceVm)
        {
            Parameters parameters =
                _parametersProcessorService.ProcessParameters(Request.RouteValues, Request.QueryString);
            string?query = _sparqlFactoryService.GetFinalPutQueryForResource(parameters, resourceVm);

            if (query != null)
            {
                bool successful = await _endpointService.ExecuteUpdateSparqlQueryAsync(
                    parameters.RouteParameters.Endpoint,
                    parameters.RouteParameters.Graph, query);

                if (successful)
                {
                    return(Created(new Uri(Request.GetEncodedUrl()), resourceVm));
                }
            }

            return(BadRequest(new ValidationErrorVm()
            {
                CustomError = new CustomErrorVm()
                {
                    CustomErrorMessage =
                        $"Resource could not have been created! Check selected endpoint configuration at {UrlHelperClass.GetEndpointUrl(Request.GetEncodedUrl())}.",
                    GeneratedQuery = query
                }
            }));
        }