Exemple #1
0
        /// <summary>
        /// Message Getter.
        /// This method gets a message being given its code.
        /// </summary>
        /// <param name="code">The message code.</param>
        /// <returns>A MessageBE is returned.</returns>
        public static MessageBE getMessage(int code)
        {
            MessageBE message = new MessageBE();

            UserDAC user = new UserDAC();
            int read = 0, delSnd = 0, delAddr = 0;

            SqlConnection c = new SqlConnection(connection);
            c.Open();
            SqlCommand com = new SqlCommand("SELECT * FROM message WHERE code= " + code.ToString(), c);

            SqlDataReader dr = com.ExecuteReader();

            while (dr.Read())
            {
                message.code = int.Parse(dr["code"].ToString());
                message.Sender = user.getUser(dr["sender"].ToString());
                message.Addressee = user.getUser(dr["addressee"].ToString());
                message.Subject = dr["issue"].ToString();
                message.Message = dr["body"].ToString();
                message.Date = DateTime.Parse(dr["date"].ToString());
                read = int.Parse(dr["isread"].ToString());
                delSnd = int.Parse(dr["deleted_sender"].ToString());
                delAddr = int.Parse(dr["deleted_reader"].ToString());
                message.ConversCode = int.Parse(dr["convers_code"].ToString());
            }

            message.Read = false;
            message.DelSender = false;
            message.DelAddressee = false;
            if (read == 1) message.Read = true;
            if (delSnd == 1) message.DelSender = true;
            if (delAddr == 1) message.DelAddressee = true;

            c.Close();

            return message;
        }
Exemple #2
0
        /* Gets all messages */
        public List<MessageBE> getAllMessages()
        {
            List<MessageBE> messages = new List<MessageBE>();
            MessageBE tempM = new MessageBE();
            UserDAC user = new UserDAC();

            SqlConnection c = new SqlConnection(connection);
            c.Open();
            SqlCommand com = new SqlCommand("SELECT * FROM Messages", c);
            SqlDataReader dr = com.ExecuteReader();

            while (dr.Read())
            {
                tempM = new MessageBE();
                tempM.code = int.Parse(dr["code"].ToString());
                tempM.Sender = user.getUser(dr["sender"].ToString());
                tempM.Addressee = user.getUser(dr["addressee"].ToString());
                tempM.Subject = dr["issue"].ToString();
                tempM.Message = dr["body"].ToString();
                tempM.Date = DateTime.Parse(dr["date"].ToString());
                tempM.Read = bool.Parse(dr["isread"].ToString());
                tempM.DelSender = bool.Parse(dr["deleted_sender"].ToString());
                tempM.DelAddressee = bool.Parse(dr["deleted_reader"].ToString());
                tempM.OriginalMessage = getMessage(int.Parse(dr["original"].ToString()));

                messages.Add(tempM);
            }

            c.Close();

            return messages;
        }
Exemple #3
0
        /* Gets a single message by its code */
        public MessageBE getMessage(int code)
        {
            MessageBE message = null;

            if (code == null)
            {
                UserDAC user = new UserDAC();

                SqlConnection c = new SqlConnection(connection);
                c.Open();
                SqlCommand com = new SqlCommand("SELECT * FROM Messages WHERE code='" + code.ToString() + "'", c);

                SqlDataReader dr = com.ExecuteReader();

                while (dr.Read())
                {
                    message.code = int.Parse(dr["code"].ToString());
                    message.Sender = user.getUser(dr["sender"].ToString());
                    message.Addressee = user.getUser(dr["addressee"].ToString());
                    message.Subject = dr["issue"].ToString();
                    message.Message = dr["body"].ToString();
                    message.Date = DateTime.Parse(dr["date"].ToString());
                    message.Read = bool.Parse(dr["isread"].ToString());
                    message.DelSender = bool.Parse(dr["deleted_sender"].ToString());
                    message.DelAddressee = bool.Parse(dr["deleted_reader"].ToString());
                    message.OriginalMessage = getMessage(int.Parse(dr["original"].ToString()));
                }

                c.Close();
            }

            return message;
        }
Exemple #4
0
        /* If addresee is NULL, gets the list of sent messages by sender.
         * If sender is NULL, gets the list of received messages by addresee.
         * If anyone is NULL, gets the list of messages traded by sender and addressee. */
        public List<MessageBE> getMessages(UserBE sender, UserBE addressee)
        {
            List<MessageBE> messages = new List<MessageBE>();
            if (sender == null && addressee == null)
            {
                MessageBE tempM = new MessageBE();
                UserDAC user = new UserDAC();

                SqlConnection c = new SqlConnection(connection);
                c.Open();
                SqlCommand com;

                if (sender == null)
                {
                    com = new SqlCommand("SELECT * FROM Messages WHERE addressee='" + addressee.Email + "'", c);
                }
                else if (addressee == null)
                {
                    com = new SqlCommand("SELECT * FROM Messages WHERE sender='" + sender.Email + "'", c);
                }
                else
                {
                    com = new SqlCommand("SELECT * FROM Messages WHERE sender='" + sender.Email + "' and addressee='" + addressee.Email + "'", c);
                }
                SqlDataReader dr = com.ExecuteReader();

                while (dr.Read())
                {
                    tempM = new MessageBE();
                    tempM.code = int.Parse(dr["code"].ToString());
                    tempM.Sender = user.getUser(dr["sender"].ToString());
                    tempM.Addressee = user.getUser(dr["addressee"].ToString());
                    tempM.Subject = dr["issue"].ToString();
                    tempM.Message = dr["body"].ToString();
                    tempM.Date = DateTime.Parse(dr["date"].ToString());
                    tempM.Read = bool.Parse(dr["isread"].ToString());
                    tempM.DelSender = bool.Parse(dr["deleted_sender"].ToString());
                    tempM.DelAddressee = bool.Parse(dr["deleted_reader"].ToString());
                    tempM.OriginalMessage = getMessage(int.Parse(dr["original"].ToString()));

                    messages.Add(tempM);
                }

                c.Close();
            }

            return messages;
        }
Exemple #5
0
 /// <summary>
 /// User Retrieval.
 /// Retrieves an user from the database using the current user email.
 /// </summary>
 /// <returns>The full user recovered from the DB.</returns>
 public UserBE getUserByEmail()
 {
     UserDAC userDAC = new UserDAC();
     return userDAC.getUser(this.Email);
 }