Advertisement
Guest User

Untitled

a guest
May 5th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. [ResponseType(typeof(Product))]
  2. public IHttpActionResult Put(int id, [FromBody]Product product)
  3. {
  4. try
  5. {
  6.  
  7. if (product == null)
  8. {
  9. return BadRequest("Product cannot be null");
  10. }
  11. if (!ModelState.IsValid)
  12. {
  13. return BadRequest(ModelState);
  14. }
  15. var oldProduct = db.Products.Find(id);
  16. if (oldProduct == null)
  17. {
  18. return BadRequest("No such product");
  19. }
  20. db.Products.Remove(oldProduct);
  21. db.Products.Add(product);
  22. return Ok();
  23.  
  24. }
  25. catch (Exception ex)
  26. {
  27.  
  28. return InternalServerError(ex);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement