Ami*_*adi 5 asp.net rest patch asp.net-web-api json-patch
I'm looking for a way to validate and check the values of the model that is sent to my PATCH method for updating. I haven't found my answer yet.
我已经阅读了 JsonPatch 文档,但没有找到我想要的。
场景:我有一个 RESTful Web API,并且说我有一个名为“users”的资源。假设客户端想要部分更新“用户”资源:(PATCH api/users/{id}),例如,当客户端发送 JsonPatch 文档时,我必须检查是否发送电子邮件进行更新,如果是,我必须检查电子邮件是否重复。那么,我怎么能用下面这样的方法来做到这一点:(我使用 ASP.NET Web API)
[HttpPatch]
[Route("{userId}")]
public HttpResponseMessage UpdateUser(int userId, JsonPatch.JsonPatchDocument<User> patchDocument)
{
// I could do this but before that I wanna validate the proeprties:
patchDocument.ApplyUpdatesTo(dbContext.Users.Single(u => u.Id == userId));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1037 次 |
最近记录: |