Ejemplo n.º 1
0
 public void update()
 {
     UserDAC userDAC = new UserDAC();
     userDAC.updateUser(this);
 }
Ejemplo n.º 2
0
        public bool verifyUser()
        {
            UserDAC userDAC = new UserDAC();
            UserBE otro = userDAC.getUserByNick(nickname);

            if (otro.nickname == nickname && otro.password == password)
            {
                this.Name = otro.Name;
                this.LastName = otro.LastName;
                this.Zipcode = otro.Zipcode;
                this.Email = otro.Email;
                this.Address = otro.Address;
                this.Credit = otro.Credit;
                this.LastConnection = otro.LastConnection;
                this.ProfilePicture = otro.ProfilePicture;

                return true;
            }
            else
                return false;
        }
Ejemplo n.º 3
0
        /* ****************************************************************** */
        /* Methods                                                            */
        /* ****************************************************************** */
        public string create()
        {
            string result = "";
            UserDAC userDAC = new UserDAC();

            result = userDAC.insertUser(this);

            return result;
        }
Ejemplo n.º 4
0
 public void delete()
 {
     UserDAC userDAC = new UserDAC();
     userDAC.deleteUser(email);
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// User Authentication.
        /// This method uses the data access component to verify that the
        /// current user exists in the database and authenticate it in case
        /// the user exists by comparing passwords. If authenticated,
        /// the current user gets all the fields from the obtained user.
        /// </summary>
        /// <returns>True if the has been properly authenticated and false 
        ///     otherwise (no matter what reason).</returns>
        public bool verifyUser()
        {
            bool verified = false;

            UserDAC userDAC = new UserDAC();
            // Obtain the full user with the same nickname from the database.
            UserBE authUser = userDAC.getByNick(nickname);

            string auxiliar = authUser.Password;

            // Compare the nicknames, taking into account that if the user
            // is not present in the database the fields will be empty
            // and then the nicknames will not match. Compare the
            // passwords to authenticate.
            if (authUser.nickname == nickname && ValidatePassword(password, authUser.password))
            {
                this.Name = authUser.Name;
                this.LastName = authUser.LastName;
                this.Email = authUser.Email;
                this.Credit = authUser.Credit;
                this.ProfilePicture = authUser.ProfilePicture;

                verified = true;
            }

            return verified;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// User Retrieval.
 /// Retrieves an user from the database using the current user nickname.
 /// </summary>
 /// <returns>The full user recovered from the DB.</returns>
 public UserBE getUserByNick()
 {
     UserDAC userDAC = new UserDAC();
     return userDAC.getByNick(nickname);
 }
Ejemplo n.º 11
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);
 }