public static void addNewMessage(Message newMessage) { db.Open(); var command = db.CreateCommand(); var to = newMessage.to; var from = newMessage.from; var message = newMessage.text; var date = newMessage.date; //Inserting data command.CommandText = "INSERT INTO messages(toCol, fromCol, message, dateCol) values (" + to + "," + from + ",'" + message + "','" + date + "')"; command.ExecuteNonQuery(); db.Close(); }
public static void insertMessages(Message m) { dbcon.Open(); SQLiteCommand insert = new SQLiteCommand("INSERT INTO Message_Table(Mto,Mfrom,text) values (@MTO,@MFROM,@MTEXT)", dbcon); insert.Parameters.AddWithValue("MTO",m.to.ToString()); insert.Parameters.AddWithValue("MFROM",m.from.ToString()); insert.Parameters.AddWithValue("MTEXT",m.text); try{ insert.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } dbcon.Close(); }
private void SendMessage(object sender, RoutedEventArgs e) { string toSend = MBody.Text; if (toSend != "") { ServicesConsume.PostMessages(ContactInfo.userId, toSend); Message tmp = new Message(ContactInfo.userId,3,toSend); List<Message> List = new List<Message>(); List.Add(tmp); MessagesContext.insertMessages(List); MBody.Text = ""; } else { MessageBox.Show("No puedes enviar un mensaje vacío"); } }
private void Send_message(object sender, RoutedEventArgs e) { string text = textToSend.Text; string json = "{ " + '"' + "from" + '"'+ ":" + 3 + "," + '"'+"to"+ '"'+ ":" + contactId + "," + '"' + "text" + '"' + ":"+'"'+ text + '"' + "}"; Console.WriteLine(json); var client = new RestClient("http://localhost:8090"); var request = new RestRequest("rest/messages", Method.POST); request.AddParameter("application/json", json, ParameterType.RequestBody); // execute the request //calling server with restClient var result = client.ExecuteAsync(request, (response) => { if (response.StatusCode == HttpStatusCode.OK) { //upload successfull DateTime localDate = DateTime.Now; Message newMessage = new Message(3, contactId, text, localDate.ToString()); messages.Add(newMessage); DBmanager.addNewMessage(newMessage); } else { //error ocured during upload MessageBox.Show("There was a problem sending the message, please try again"); } }); }