public bool UpdateSosMessage(Guid sosId, SosUpdate updateSosMessage) { MySqlConnection conn = null; try { conn = ConnectionManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(UPDATE_SOS_MESSAGE, conn); cmd.Parameters.AddWithValue("@guid", sosId); cmd.Parameters.AddWithValue("@last_update", updateSosMessage.LastUpdate); cmd.Parameters.AddWithValue("@lat", updateSosMessage.Lat); cmd.Parameters.AddWithValue("@longi", updateSosMessage.Longi); cmd.Parameters.AddWithValue("@message", updateSosMessage.Message); int numOfRows = cmd.ExecuteNonQuery(); if (numOfRows == 1) { return(true); } } catch (MySql.Data.MySqlClient.MySqlException ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(false); }
// PUT: api/Sos/5 public HttpResponseMessage Put(string id, [FromBody] string value) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Conflict, id); try { SosUpdate sosUpdate = JsonConvert.DeserializeObject <SosUpdate>(value); bool result = new SosMessageDAO().UpdateSosMessage(Guid.Parse(id), sosUpdate); if (result) { response = Request.CreateResponse(HttpStatusCode.OK, sosUpdate.LastUpdate); response.Headers.Location = new Uri(Request.RequestUri, string.Format("sos/{0}", id)); return(response); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(response); }