Exemple #1
0
        public virtual async Task <IActionResult> PatchAsync([FromBody] OperationsDocument doc)
        {
            if (doc == null)
            {
                return(new StatusCodeResult(422));
            }

            var results = await _operationsProcessor.ProcessAsync(doc.Operations);

            return(Ok(new OperationsDocument(results)));
        }
        // https://github.com/json-api/json-api/blob/999e6df77b28549d6c37b163b73c8e9102400020/_format/1.1/index.md#-processing-operations
        public async Task <string> PerformOperations(string json)
        {
            var document = JsonConvert.DeserializeObject <OperationsDocument>(json);

            // { json:api } operations requires that we use GUIDs for ids so that
            // relationships can be properly mapped in a request between multiple
            // records. Most of our models do not use GUIDs, so for those that do
            // not, we need to delete the ID field for any 'add' operations.
            document.Operations.ForEach(operation => {
                if (operation.Op == OperationCode.add)
                {
                    (operation.Data as dynamic).Id = null;
                }
            });

            var results = await this._operationsProcessor.ProcessAsync(document.Operations);

            var response = new OperationsDocument(results);

            return(JsonConvert.SerializeObject(response));
        }