Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public HttpResponseMessage Put(long id, [FromBody]Person value)
  2. {
  3. PersonPersistence pp = new PersonPersistence();
  4. bool recordExisted = false;
  5. recordExisted = pp.updatePerson(id, value);
  6.  
  7. HttpResponseMessage response;
  8. if (recordExisted)
  9. {
  10. response = Request.CreateResponse(HttpStatusCode.NoContent);
  11. }
  12. else
  13. {
  14. response = Request.CreateResponse(HttpStatusCode.NotFound);
  15. }
  16. return response;
  17. }
  18.  
  19. public bool updatePerson(long ID,Person personToSave)
  20. {
  21. SqlDataReader mySQLReader = null;
  22.  
  23. String sqlString = "Select * FROM [Table] WHERE ID = " + ID.ToString();
  24. SqlCommand cmd = new SqlCommand(sqlString, conn);
  25.  
  26. mySQLReader = cmd.ExecuteReader();
  27. if (mySQLReader.Read())
  28. {
  29. mySQLReader.Close();
  30. sqlString = "Update [Table] set FirstName='" + personToSave.FirstName + "', LastName='" + personToSave.LastName + "', PayRate='" + personToSave.PayRate + "', StartDate='" + personToSave.StartDate.ToString("yyyy-MM-dd HH:mm:ss") + "', EndDate='" + personToSave.EndDate.ToString("yyyy-MM-dd HH:mm:ss") + "' Where ID= " + ID.ToString();
  31.  
  32.  
  33. cmd = new SqlCommand(sqlString, conn);
  34.  
  35. cmd.ExecuteNonQuery();
  36. return true;
  37.  
  38. }
  39. else
  40. return false;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement