Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public HttpResponseMessage Put(long id, [FromBody]Person value)
- {
- PersonPersistence pp = new PersonPersistence();
- bool recordExisted = false;
- recordExisted = pp.updatePerson(id, value);
- HttpResponseMessage response;
- if (recordExisted)
- {
- response = Request.CreateResponse(HttpStatusCode.NoContent);
- }
- else
- {
- response = Request.CreateResponse(HttpStatusCode.NotFound);
- }
- return response;
- }
- public bool updatePerson(long ID,Person personToSave)
- {
- SqlDataReader mySQLReader = null;
- String sqlString = "Select * FROM [Table] WHERE ID = " + ID.ToString();
- SqlCommand cmd = new SqlCommand(sqlString, conn);
- mySQLReader = cmd.ExecuteReader();
- if (mySQLReader.Read())
- {
- mySQLReader.Close();
- 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();
- cmd = new SqlCommand(sqlString, conn);
- cmd.ExecuteNonQuery();
- return true;
- }
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement