public List<Message> getAllMessages( ) { List<Message> messages = new List<Message> (); string sql = "SELECT " + "`messages`.`id`, " + "`messages`.`nuberReceiver`, " + "`messages`.`message`, " + "`messages`.`sendAt`, " + "`messages`.`contactId` " + "FROM SmsApplicatie.messages"; MySqlCommand statement = this.databaseConnection.CreateCommand (); statement.CommandText = sql; MySqlDataReader reader = statement.ExecuteReader (); while (reader.Read ()) { Message message = new Message (); message.setId ( Convert.ToUInt32( reader ["id"] )); message.setNumberReceiver ( Convert.ToString( reader ["nuberReceiver"] )); message.setMessageBody ( Convert.ToString(reader ["message"])); message.setSendAt ( Convert.ToDateTime( reader ["sendAt"] )); messages.Add (message); } return messages; }
public Message getMessageById( UInt32 id ) { string sql = "`SELECT " + "messages`.`id`, " + "`messages`.`nuberReceiver`, " + "`messages`.`message`, " + "`messages`.`sendAt`, " + "`messages`.`contactId` " + "FROM SmsApplicatie.messages " + "WHERE id=:id"; MySqlCommand statement = this.databaseConnection.CreateCommand (); statement.CommandText = sql; statement.Parameters.AddWithValue ("id", id.ToString ()); MySqlDataReader reader = statement.ExecuteReader (); if (reader.Read ()) { Message message = new Message ( Convert.ToUInt32( reader["id"] ), Convert.ToString( reader["nuberReceiver"] ), Convert.ToString( reader["message"] ), Convert.ToDateTime( reader["sendAt"] ), Convert.ToUInt32( reader["contactId"] ) ); return new Message (); } return null; }
public void sendMessage( Message message ) { ViaNetApiCall viaNetApiModel = new ViaNetApiCall (); ViaNetApiCall.Result callResult; callResult = viaNetApiModel.sendSMS ( message ); if (callResult.Success) { // Message is send successfully this.messageRepo.insertMessege ( message ); } else { throw new ApplicationException ("[Code] " + callResult.ErrorCode + " [Message] " + callResult.ErrorMessage); } }
public Result sendSMS( Message message ) { return this.sendSMS (this.telephoneNumberSender, message.getNumberReceiver (), message.getMessageBody ()); }
public void updateMessage ( Message message) { string sql = "UPDATE `SmsApplicatie`.`messages` " + "SET numberReceiver=:numberReceiver, message=:message, sendAt=:sendAt, contactId=:contactId" + "where id=:id"; MySqlCommand statement = this.databaseConnection.CreateCommand (); statement.CommandText = sql; statement.Prepare (); statement.Parameters.AddWithValue ( "numberReceiver", message.getNumberReceiver() ); statement.Parameters.AddWithValue ( "message", message.getMessageBody() ); statement.Parameters.AddWithValue ( "sendAt", message.getSendAt() ); statement.Parameters.AddWithValue ( "contactId", message.getContactId() ); statement.Parameters.AddWithValue ( "id", message.getId() ); }
public void deleteMessage ( Message message) { string sql = "DELETE FROM `SmsApplicatie`.`messages` WHERE id=:id"; MySqlCommand statement = this.databaseConnection.CreateCommand (); statement.CommandText = sql; statement.Prepare (); statement.Parameters.AddWithValue ( "id", message.getId() ); if ( statement.ExecuteNonQuery () > 0 ) { throw new ApplicationException ("Can not delete message with id: " + message.getId()); } }
public void insertMessege ( Message message) { string sql = "INSERT INTO `SmsApplicatie`.`messages`( numberReceiver, message, sendAt, contactId ) " + "VALUES ( :numberReceiver, :message, :sendAt, :contactId )"; MySqlCommand statement = this.databaseConnection.CreateCommand (); statement.CommandText = sql; statement.Prepare (); statement.Parameters.AddWithValue ( "numberReceiver", message.getNumberReceiver() ); statement.Parameters.AddWithValue ("message", message.getMessageBody () ); statement.Parameters.AddWithValue ("sendAt", Convert.ToString (message.getSendAt ())); statement.Parameters.AddWithValue ("contactId", message.getContactId ()); if ( statement.ExecuteNonQuery () == 0 ){ throw new ApplicationException (); } }