実際のクライアント呼び出しやこれらのAPIメソッドのサーバー実装に問題はありませんが、これ以上の提案はありません。以下のようなものAngular APIのPUT-DELETEメソッドが404を返すことがありません。
"/api/Product/"
:APIの実装
[HttpPut()]
public IHttpActionResult Put(int id,
Product product) {
IHttpActionResult ret = null;
PTCViewModel vm = new PTCViewModel();
vm.Entity = product;
vm.PageMode = PageConstants.EDIT;
vm.Save();
if (vm.IsValid) {
ret = Ok(product);
}
else if (vm.Messages.Count > 0) {
ret = BadRequest(ConvertToModelState(vm.Messages));
}
else {
ret = NotFound();
}
return ret;
}
[HttpDelete()]
public IHttpActionResult Delete(int id) {
IHttpActionResult ret = null;
PTCViewModel vm = new PTCViewModel();
// Get the product
vm.Entity = vm.Get(id);
// Did we find the product?
if (vm.Entity.ProductId > 0) {
// Delete the product
vm.Delete(id);
ret = Ok(true);
}
else {
ret = NotFound();
}
return ret;
}