/// <summary>
 /// Updates the message status.
 /// </summary>
 /// <param name="status">The message status.</param>
 /// <returns></returns>
 public static bool UpdateStatus(IMessage message, MessageStatus status)
 {
     try
     {
         // Update message status in database
         OutgoingMessage outgoingMessage = OutgoingMessage.SingleOrDefault(msg => msg.Id == message.Identifier);
         if (outgoingMessage == null)
         {
             return(false);
         }
         outgoingMessage.Status     = StringEnum.GetStringValue(status);
         outgoingMessage.LastUpdate = DateTime.Now;
         if (status == MessageStatus.Sent)
         {
             outgoingMessage.SentDate = outgoingMessage.LastUpdate;
         }
         outgoingMessage.Update();
     }
     catch (Exception ex)
     {
         log.Error(string.Format("Error updating message: {0} ", ex.Message), ex);
         return(false);
     }
     return(true);
 }
 /// <summary>
 /// Handles the Click event of the tsbMessageDelete control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void tsbMessageDelete_Click(object sender, EventArgs e)
 {
     try
     {
         // Delete the message
         if (this.Message.GetType() == typeof(IncomingMessage))
         {
             // Delete the message
             IncomingMessage msg = this.Message as IncomingMessage;
             if (StringEnum.GetStringValue(MessageStatus.Archived).Equals(msg.Status))
             {
                 DialogResult result = FormHelper.Confirm(Resources.MsgConfirmDeleteMessage);
                 if (result == DialogResult.Yes)
                 {
                     // Physically delete the message
                     msg.Delete();
                     RefreshMessageView(ViewAction.RefreshArchivedInbox);
                     FormHelper.ShowInfo(Resources.MsgMessageDeleted);
                 }
             }
             else
             {
                 // Set the message status to "Archived"
                 msg.Status = StringEnum.GetStringValue(MessageStatus.Archived);
                 msg.Update();
                 RefreshMessageView(ViewAction.RefreshArchivedInbox);
                 RefreshMessageView(ViewAction.RefreshInbox);
                 FormHelper.ShowInfo(Resources.MsgMessageArchived);
             }
         }
         else if (this.Message.GetType() == typeof(OutgoingMessage))
         {
             // Delete the message
             OutgoingMessage msg = this.Message as OutgoingMessage;
             if (StringEnum.GetStringValue(MessageStatus.Archived).Equals(msg.Status))
             {
                 DialogResult result = FormHelper.Confirm(Resources.MsgConfirmDeleteMessage);
                 if (result == DialogResult.Yes)
                 {
                     // Physically delete the message
                     msg.Delete();
                     RefreshMessageView(ViewAction.RefreshArchivedOutbox);
                     FormHelper.ShowInfo(Resources.MsgMessageDeleted);
                 }
             }
             else
             {
                 // Set the message status to "Archived"
                 msg.Status = StringEnum.GetStringValue(MessageStatus.Archived);
                 msg.Update();
                 RefreshMessageView(ViewAction.RefreshArchivedOutbox);
                 RefreshMessageView(ViewAction.RefreshOutbox);
                 FormHelper.ShowInfo(Resources.MsgMessageArchived);
             }
         }
     }
     catch (Exception ex)
     {
         FormHelper.ShowError(ex.Message);
     }
 }