KevinDockx / JsonPatch

JSON Patch (JsonPatchDocument) RFC 6902 implementation for .NET
MIT License
174 stars 28 forks source link

Protected Properties and methods #77

Closed AndiRudi closed 7 years ago

AndiRudi commented 7 years ago

I am wondering how the following use case would be solved. Image you have a course entity containing a trainer and then several units with each also a trainer. If you create the course and units you have the trainer copied down to all units.

Now you issue a PATCH call to the trainer field in the course. You want some logic that updates all units of the course as well (don't matter if it makes sense or not for now). In our application we made the trainer of the course a protected property and added a method UpdateTrainer which would do the job to update the units.

To get that working with a PATCH we had to create an UpdateCourse ViewModel which - when the trainer was set and the trainer was different than the stored one - called the UpdateTrainer method.

The question is, how that works with the JsonPatchDocument.

Thanks for any help

KevinDockx commented 7 years ago

The patch should update a DTO. After that one has been updated, the code to map that updated DTO back into your entity is beyond the responsibility of what the patch does, but I think you should still be able to call that update method during your mapping. If required, you can always look into the Operations property of the patchdoc.

KevinDockx commented 7 years ago

I'll close this as it seems to be solved - if it needs to be reopened, just ask :)