Esempio n. 1
0
        public static bool Register()
        {
            ICollection <User> users = DBUser.ReadUsers();

            ConsoleUI.ShowLine("press 0 anytime to exit");
            bool exit;

            exit = ConsoleUI.GetString(out string username, "give username: "******"give password: "******"repeat password: "******"passwords are not the same!!");
                return(false);
            }

            string encryptedPassword = CryptoManager.EncryptPassword(password1, out string encryptedSalt);

            try
            {
                int headMasterSaved = DBUser.CreateUser(username, encryptedPassword, encryptedSalt, "headmaster", out int id);
                if (headMasterSaved == 0)
                {
                    throw new Exception("head master NOT saved");
                }
            }
            catch (Exception e)
            {
                ConsoleUI.ShowLine(e.Message);
                ConsoleUI.ReadKey();
                return(false);
            }

            ConsoleUI.ShowLine("head master created");

            ConsoleUI.ReadKey();

            return(true);
        }
Esempio n. 2
0
        public static void AutoGenerate()
        {
            ConsoleUI.ShowLine("Creating headmaster with username: '******' and password: '******'");

            string encryptedPassword = CryptoManager.EncryptPassword("12345", out string encryptedSalt);

            try
            {
                int headMasterSaved = DBUser.CreateUser("hm", encryptedPassword, encryptedSalt, "headmaster", out int id);
                if (headMasterSaved == 0)
                {
                    throw new Exception("head master NOT saved");
                }
            }
            catch (Exception e)
            {
                ConsoleUI.ShowLine(e.Message);
                ConsoleUI.ReadKey();
                return;
            }

            ConsoleUI.ShowLine("head master created");

            ConsoleUI.ShowLine("creating students");

            List <int> studentIDs    = new List <int>();
            List <int> trainerIDs    = new List <int>();
            List <int> assignmentIDs = new List <int>();
            List <int> courseIDs     = new List <int>();

            int    studentID;
            string studentUsername;
            string plainTextPassword;
            string studentFName;
            string studentLName;

            // 3 students
            for (int i = 0; i < 3; i++)
            {
                studentUsername   = "******" + i;
                plainTextPassword = "******" + i;

                encryptedPassword = CryptoManager.EncryptPassword(plainTextPassword, out encryptedSalt);

                DBUser.CreateUser(studentUsername, encryptedPassword, encryptedSalt, "student", out studentID);

                ConsoleUI.ShowLine($"student user created u:{studentUsername} p:{plainTextPassword}");

                studentFName = "studentFirstName" + i;

                studentLName = "studentLastName" + i;

                DBStudent.CreateStudent(studentFName, studentLName, new DateTime(2000, 1, 1), 20000, studentID);

                ConsoleUI.ShowLine($"student {studentFName} {studentLName} created");

                studentIDs.Add(studentID);

                ConsoleUI.ChangeLine();
            }

            int    trainerID;
            string trainerUsername;
            string trainerFName;
            string trainerLName;
            string trainerSubject;

            // 2 trainers
            for (int i = 0; i < 2; i++)
            {
                trainerUsername   = "******" + i;
                plainTextPassword = "******" + i;

                encryptedPassword = CryptoManager.EncryptPassword(plainTextPassword, out encryptedSalt);

                DBUser.CreateUser(trainerUsername, encryptedPassword, encryptedSalt, "trainer", out trainerID);

                ConsoleUI.ShowLine($"trainer user created u:{trainerUsername} p:{plainTextPassword}");

                trainerFName = "trainerFirstName" + i;

                trainerLName = "trainerLastName" + i;

                trainerSubject = "trainerSubject" + i;

                DBTrainer.CreateTrainer(trainerFName, trainerLName, trainerSubject, trainerID);

                ConsoleUI.ShowLine($"trainer {trainerFName} {trainerLName} created");

                trainerIDs.Add(trainerID);

                ConsoleUI.ChangeLine();
            }

            string title;
            string description;

            // 2 assignments
            for (int i = 0; i < 2; i++)
            {
                title       = "assignmentTitle" + i;
                description = "assignmentDescription" + i;

                DBAssignment.CreateAssignment(title, description, new DateTime(2019, 1, 1), 100, 100, out int assignmentID);

                assignmentIDs.Add(assignmentID);

                ConsoleUI.ShowLine($"assignment {title} with id: {assignmentID} created");

                ConsoleUI.ChangeLine();
            }

            // 3 courses
            for (int i = 0; i < 3; i++)
            {
                title = "courseTitle" + i;

                DBCourse.CreateCourse(title, "C#", "Full time", new DateTime(2019, 1, 1), new DateTime(2019, 2, 2), out int courseID);

                courseIDs.Add(courseID);

                ConsoleUI.ShowLine($"course {title} with id: {courseID} created");

                ConsoleUI.ChangeLine();
            }

            AssignmentPerStudentManager a = new AssignmentPerStudentManager();

            //assignments-courses
            //all assignments to course 1
            #region
            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[0], courseIDs[0]);
            a.CreateFromNewAssignment(assignmentIDs[0], courseIDs[0]);

            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[1], courseIDs[0]);
            a.CreateFromNewAssignment(assignmentIDs[1], courseIDs[0]);

            #endregion

            //first 3 assignments to course 1
            #region
            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[0], courseIDs[1]);
            a.CreateFromNewAssignment(assignmentIDs[0], courseIDs[1]);

            DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[1], courseIDs[1]);
            a.CreateFromNewAssignment(assignmentIDs[1], courseIDs[1]);

            #endregion

            //student courses
            //all students to course 1
            #region
            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[0]);
            a.CreateFromNewStudent(studentIDs[0], courseIDs[0]);

            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[1], courseIDs[0]);
            a.CreateFromNewStudent(studentIDs[1], courseIDs[0]);

            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[2], courseIDs[0]);
            a.CreateFromNewStudent(studentIDs[2], courseIDs[0]);

            #endregion

            // 2 students to course 2
            #region
            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[1]);
            a.CreateFromNewStudent(studentIDs[0], courseIDs[1]);

            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[1], courseIDs[1]);
            a.CreateFromNewStudent(studentIDs[1], courseIDs[1]);

            #endregion
            // 2 courses to student 1
            #region
            DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[2]);
            a.CreateFromNewStudent(studentIDs[0], courseIDs[2]);

            #endregion


            //trainer courses

            //all trainers to course 1
            #region
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[0]);
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[1], courseIDs[0]);
            #endregion

            // 2 trainers to course 2
            #region
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[1]);
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[1], courseIDs[1]);
            #endregion

            //2 courses to trainer 1
            #region
            DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[2]);
            #endregion

            ConsoleUI.ShowLine("done");
        }
Esempio n. 3
0
        public void Create()
        {
            bool exit;

            while (true)
            {
                ConsoleUI.Clear();

                string baseMessage = "type trainer's information or type 0 to exit \n";

                exit = ConsoleUI.GetString(out string username, $"{baseMessage}Trainer's username: "******"{baseMessage}Trainer's password: "******"{baseMessage}Trainer's first name: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetString(out string lname, $"{baseMessage}Trainer's last name: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetString(out string subject, $"{baseMessage}Trainer's subject: ");
                if (exit)
                {
                    return;
                }

                int trainerID;

                string encryptedPassword = CryptoManager.EncryptPassword(password, out string encryptedSalt);

                try
                {
                    int userSaved = DBUser.CreateUser(username, encryptedPassword, encryptedSalt, "trainer", out trainerID);
                    if (userSaved == 0)
                    {
                        throw new Exception("user NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine($"user {username} saved");

                try
                {
                    int trainerSaved = DBTrainer.CreateTrainer(fname, lname, subject, trainerID);
                    if (trainerSaved == 0)
                    {
                        throw new Exception("trainer NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("trainer created");

                ConsoleUI.ReadKey();
            }
        }
Esempio n. 4
0
        public void Create()
        {
            bool exit;

            while (true)
            {
                ConsoleUI.Clear();

                string baseMessage = "type student's information or type 0 to exit \n";

                exit = ConsoleUI.GetString(out string username, $"{baseMessage}Student's username: "******"{baseMessage}Student's password: "******"{baseMessage}Student's first name: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetString(out string lname, $"{baseMessage}Student's last name: ");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetDate(out DateTime? dob, "Student's date of birth:\n");
                if (exit)
                {
                    return;
                }

                exit = ConsoleUI.GetDecimal(out decimal fees, "Student's fees: ");
                if (exit)
                {
                    return;
                }

                int studentID;

                string encryptedPassword = CryptoManager.EncryptPassword(password, out string encryptedSalt);

                try
                {
                    int userSaved = DBUser.CreateUser(username, encryptedPassword, encryptedSalt, "student", out studentID);
                    if (userSaved == 0)
                    {
                        throw new Exception("user NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine($"user {username} saved");

                try
                {
                    int studentSaved = DBStudent.CreateStudent(fname, lname, (DateTime)dob, fees, studentID);
                    if (studentSaved == 0)
                    {
                        throw new Exception("student NOT saved");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("student created");

                ConsoleUI.ReadKey();
            }
        }