public IList<UserMessage> GetMessagesByUserID(int userid)
        {
            IList<UserMessage> userlist = new List<UserMessage>();
            SqlServerUtility sql = new SqlServerUtility();

            sql.AddParameter("@User_ID", SqlDbType.Int, userid);

            SqlDataReader reader = sql.ExecuteSqlReader(SqlGetMessagesByUserId);

            if (reader != null)
            {
                while (reader.Read())
                {
                    UserMessage usermessage = new UserMessage();

                    if (!reader.IsDBNull(0)) usermessage.Id = reader.GetInt32(0);
                    if (!reader.IsDBNull(1)) usermessage.UserID = reader.GetInt32(1);
                    if (!reader.IsDBNull(2)) usermessage.MessageID = reader.GetInt32(2);
                    if (!reader.IsDBNull(3)) usermessage.UserMessageState = reader.GetInt32(3);

                    usermessage.MarkOld();

                    userlist.Add(usermessage);
                }
                reader.Close();
            }

            return userlist;
        }
        public UserMessage GetUserMessageByUserIdandMsgId(int userid, int messageid)
        {
            UserMessage usermessage = new UserMessage();
            SqlServerUtility sql = new SqlServerUtility();

            sql.AddParameter("@User_ID", SqlDbType.Int, userid);
            sql.AddParameter("@Message_ID", SqlDbType.Int, messageid);

            SqlDataReader reader = sql.ExecuteSqlReader(SqlGetUserMessageByUserIdAndMsgId);

            if (reader != null)
            {
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0)) usermessage.Id = reader.GetInt32(0);
                    if (!reader.IsDBNull(1)) usermessage.UserID = reader.GetInt32(1);
                    if (!reader.IsDBNull(2)) usermessage.MessageID = reader.GetInt32(2);
                    if (!reader.IsDBNull(3)) usermessage.UserMessageState = reader.GetInt32(3);

                    usermessage.MarkOld();
                }
                reader.Close();
            }
            return usermessage;
        }