Beispiel #1
0
        public static void InsertUser(string userType, string name, string password, string surname, Email email)
        {
            using (NpgsqlConnection con = new NpgsqlConnection(connectionString))
            {
                try
                {
                    con.Open();

                    string        sql = "INSERT INTO Users VALUES(@reg_num, @name, @password, @surname, @email)";
                    NpgsqlCommand cmd = new NpgsqlCommand(sql, con);


                    RegNum regNum = new RegNum(RegNum.getNextValue(userType));
                    cmd.Parameters.AddWithValue("reg_num", regNum.getRegNumString());
                    cmd.Parameters.AddWithValue("name", name);
                    cmd.Parameters.AddWithValue("password", password);
                    cmd.Parameters.AddWithValue("surname", surname);
                    cmd.Parameters.AddWithValue("email", email.getEmailAddress());
                    cmd.ExecuteNonQuery();

                    sql = "INSERT INTO " + userType + "s VALUES(@reg_num)";
                    cmd = new NpgsqlCommand(sql, con);
                    cmd.Parameters.AddWithValue("reg_num", regNum.getRegNumString());
                    cmd.ExecuteNonQuery();
                }
                catch (Exception msg)
                {
                    MessageBox.Show("There was a problem while executing this action. Please contact the developers.");
                    return;
                }
            }
        }
Beispiel #2
0
        // TODO remove static from createUser in class diagram
        public User createUser(string userType, RegNum reg_num, string password, string name, string surname, Email email)
        {
            switch (userType)
            {
            case UserTypes.STUDENT:
                return(new Student(reg_num, password, name, surname, email));

            case UserTypes.PROFESSOR:
                return(new Professor(reg_num, password, name, surname, email, Database.GetCoursesForProf(reg_num.getRegNumString())));

            case UserTypes.ADMIN:
                return(new Admin(reg_num, password, name, surname, email));

            default:
                // TODO display error message
                return(null);
            }
        }