Пример #1
0
        public static bool deleteUser(string id)
        {
            var transaction      = new DatabaseHandler.Transaction();
            int affectedRecords1 = transaction.executeCommand("DELETE FROM user_data WHERE user_id='" + id + "'");
            int affectedRecords2 = transaction.executeCommand("DELETE FROM users WHERE id='" + id + "'");

            // Obie operacja powinny usunąć nie mniej i nie więcej niż 1 rekord
            if (affectedRecords1 == 1 && affectedRecords2 == 1)
            {
                transaction.commit();
                return(true);
            }
            else
            {
                transaction.rollback();
                return(false);
            }
        }
Пример #2
0
        public static bool updateAccess(string id, string access)
        {
            var transaction     = new DatabaseHandler.Transaction();
            int affectedRecords = transaction.executeCommand("UPDATE users SET access_level='" + access + "' WHERE id='" + id + "'");

            if (affectedRecords == 1)
            {
                transaction.commit();
                return(true);
            }
            else
            {
                transaction.rollback();
                return(false);
            }
        }
Пример #3
0
        public static bool tryToRegister(string username, string password, string email, string[] data)
        {
            int    userAccessLevel = int.Parse(DatabaseHandler.selectQuery("SELECT id FROM access_levels WHERE name LIKE 'USER'").Rows[0]["id"].ToString());
            string userCMD         = "INSERT INTO users (username, password_hash, access_level) VALUES('{0}', '{1}', '{2}')";
            string userDataCMD     = "INSERT INTO user_data (user_id, email, first_name, last_name, billing_address) VALUES('{0}', '{1}', '{2}', '{3}', '{4}')";

            var transaction = new DatabaseHandler.Transaction();

            try
            {
                int userInsertSuccess = transaction.executeCommand(string.Format(userCMD, username, CalculateMD5Hash(password), userAccessLevel.ToString()));
                if (userInsertSuccess == 1)
                {
                    transaction.commit();
                    transaction = new DatabaseHandler.Transaction();
                    int userID            = int.Parse(DatabaseHandler.selectQuery("SELECT id FROM users WHERE username LIKE '" + username + "'").Rows[0]["id"].ToString());
                    int dataInsertSuccess = transaction.executeCommand(string.Format(userDataCMD, userID.ToString(), email, data[0], data[1], data[2]));
                    if (dataInsertSuccess == 1)
                    {
                        transaction.commit();
                        return(true);
                    }
                    else
                    {
                        transaction.rollback();
                    }
                }
                else
                {
                    transaction.rollback();
                }
            } catch (Exception ex)
            {
                var exeption = ex;
                transaction.rollback();
            }

            return(false);
        }