Using Delta
Listing 6-14 shows Delta
just using your model. Then, to perform a patch update over an existing resource, you call the PATCH method exposed
by the Delta
to persist in, but you should then proceed to save the original object in the DB, as its state has been modified to reflect
the updates requested by the client.
[Route("delta/{id:int}")]
public Item Patch(int id, Delta<Item> newItem)
{
var item = _items.FirstOrDefault(x => x.Id == id);
if (item == null) throw new HttpResponseException(HttpStatusCode.NotFound);
newItem.Patch(item);
//item instance is now updated
return item;
}
No comments:
Post a Comment