2

Anybody know how to update nested elements of items using asp.net core json patch?

I'm tried to use xx.Operations.Add(new Operation<DataRequestModel>("Replace", $"schedules/{scheduleId}/status", null, DataRequestStatusEnum.ExtractionFailed));

But it throws an exception The path segment '43688769-f45e-4e84-a8d6-f071c077b9ad' is invalid for an array index. when I use model.ApplyTo(dataRequest); in patch action.

Thanks for any help.

cortisol
  • 335
  • 2
  • 18

1 Answers1

0

I did that by using

Controller

    [Route("{some}/adress")]
    [HttpPatch]
    public bool YourDtoUpdate(long some, [FromBody]JsonPatchDocument<TestpDTO> testChanges)
    {
        var tsd = new TestDTO(){Nested = new NestedClass()};
        testChanges.ApplyTo(tsd);
    }

Service

    var model = new TestDTO() { Foo = "abc", Nested = new NestedClass()};
    JsonPatchDocument<TesDTO> patchDoc = new JsonPatchDocument<TestDTO>();
    patchDoc.Replace(e => e.Foo , model.Foo );
    patchDoc.Replace(e => e.Nested.Bar, model.Nested.Bar);
Reven
  • 776
  • 2
  • 8
  • 23