public int CreateMessage(Message message) { int ret = 0; using (connect = new MySqlConnection(_connectionString)) { connect.Open(); using (MySqlTransaction transaction = connect.BeginTransaction()) { try { string query = "NewMessage"; var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("mText", message.MessageBody); cmd.Parameters.AddWithValue("mEmail", message.Email); cmd.Parameters.AddWithValue("mName", message.Name); ret = int.Parse(cmd.ExecuteScalar().ToString()); transaction.Commit(); connect.Close(); } catch (InvalidOperationException ioException) { transaction.Rollback(); connect.Close(); } } } return ret; }
// Creates new message public ActionResult Create() { // Creates models MessageModel messageModel = new MessageModel(); // Holds message placeholder Message newMessage = new Message(); // Stored details for the customer newMessage.Name = Request.Form["name"]; newMessage.Email = Request.Form["email"]; newMessage.MessageBody = Request.Form["Message"]; // Creates the message messageModel.CreateMessage(newMessage); // Return created message to view return Redirect("/TWART/Index"); }
public List<Message> ListMessages() { var messageList = new List<Message>(); using (connect = new MySqlConnection(_connectionString)) { try { string query = "ListMessage"; var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure }; connect.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var message = new Message(); message.MessageID = int.Parse(reader["MID "].ToString()); message.MessageBody = reader["mText"].ToString(); message.Name = reader["mEmail"].ToString(); message.Email = reader["mName"].ToString(); messageList.Add(message); } connect.Close(); } catch (InvalidOperationException ioException) { connect.Close(); } return messageList; } }
public Message SearchMessage(Message message) { return SearchMessage(message.MessageID); }