public void Initialize()
 {
     try
     {
         email = "*****@*****.**";
         DeleteData(email);                                // Clean tables
         CreateAccount(email, "TestPassword", "TestSalt"); // Create user
         cmd = new SqlCommand("SELECT SysID FROM dbo.Users WHERE UserEmail = @email");
         cmd.Parameters.AddWithValue("@email", email);
         receiverID = (int)_messageDAO.RetrieveOneColumn(cmd); // Get SysID of user just created
         //MakeTestData(); // For creating mock data for front end testing
         //DeleteTestData();
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.ToString());
     }
 }
        public static void SendToDB(IMessage message)
        {
            var  dao = new MessageDAO();
            bool success;

            try
            {
                // TODO: Create commands

                /*
                 * <add key ="queryCreateMessage" value ="INSERT INTO dbo.InboxMessages (SysID, MessageID, PrevMessageID, SenderID, IsRead, SentDate, IsGeneral)
                 * VALUES (@rcvid, @msgid, @prevmsgid, @sendid, @read, @date, @general)"/>
                 *
                 * <add key ="queryCreateGeneralMessage" value ="INSERT INTO dbo.GeneralMessages (SysID, MessageID, MessageBody) VALUES (@rcvid, @msgid, @msgbody)"/>
                 *
                 * <add key ="queryCreateInvitation" value ="INSERT INTO dbo.Invitations (SysID, MessageID, IsAccepted) VALUES (@rcvid, @msgid, @accepted)"/>
                 */
                // Create InboxMessage
                var cmd = new SqlCommand(ConfigurationManager.AppSettings["queryCreateMessage"]);
                cmd.Parameters.AddWithValue("@rcvid", message.ReceiverID);
                cmd.Parameters.AddWithValue("@prevmsgid", message.PrevMessageID);
                cmd.Parameters.AddWithValue("@sendid", message.SenderID);
                cmd.Parameters.AddWithValue("@read", message.IsRead);
                cmd.Parameters.AddWithValue("@date", message.SentDate);
                cmd.Parameters.AddWithValue("@general", message.IsGeneral);
                success = dao.SendToDB(cmd);

                // Get MessageID
                cmd = new SqlCommand(ConfigurationManager.AppSettings["queryGetMessageID"]);
                cmd.Parameters.AddWithValue("@rcvid", message.ReceiverID);
                cmd.Parameters.AddWithValue("@sendid", message.SenderID);
                cmd.Parameters.AddWithValue("@date", message.SentDate);
                cmd.Parameters.AddWithValue("@general", message.IsGeneral);
                int messageID = (int)dao.RetrieveOneColumn(cmd);

                // Create GeneralMessage
                if (message.GetType().Equals(typeof(GeneralMessage)))
                {
                    GeneralMessage general = (GeneralMessage)message;
                    cmd = new SqlCommand(ConfigurationManager.AppSettings["queryCreateGeneralMessage"]);
                    cmd.Parameters.AddWithValue("@rcvid", message.ReceiverID);
                    cmd.Parameters.AddWithValue("@msgid", messageID);
                    cmd.Parameters.AddWithValue("@msgbody", general.MessageBody);
                } // OR
                  // Create Invitation
                else if (message.GetType().Equals(typeof(Invitation)))
                {
                    Invitation invitation = (Invitation)message;
                    cmd = new SqlCommand(ConfigurationManager.AppSettings["queryCreateInvitation"]);
                    cmd.Parameters.AddWithValue("@rcvid", message.ReceiverID);
                    cmd.Parameters.AddWithValue("@msgid", messageID);
                    cmd.Parameters.AddWithValue("@accepted", invitation.IsAccepted);
                }
                success = dao.SendToDB(cmd);

                if (!success)
                {
                    throw new Exception("Incorrect number of rows affected");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }