public void CreateFromNewStudent(int studentID, int courseID)
        {
            ICollection <Course> courses = DBAssignmentsPerCourse.ReadCoursesWithAssignments();

            Course course = courses.Where(c => c.Id == courseID).First();

            ICollection <Assignment> courseAssigments = course.Assignments;

            int result = 0;

            foreach (Assignment a in courseAssigments)
            {
                result = DBAssignmentPerStudent.CreateAssignmentPerNewStudent(studentID, courseID, a.Id);
                if (result == 0)
                {
                    ConsoleUI.ShowLine("an error occured");
                    ConsoleUI.ReadKey();
                    return;
                }
                else
                {
                    ConsoleUI.ShowLine($"assignment id: {a.Id} saved for student id: {studentID} and course id {courseID}");
                }
            }
        }
Exemple #2
0
        public void Read()
        {
            ICollection <Course> courses = DBAssignmentsPerCourse.ReadCoursesWithAssignments();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("No courses yet");
            }
            else
            {
                ConsoleUI.ShowLine("List of courses with assignments\n");
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);

                    ICollection <Assignment> CourseAssignments = c.Assignments.ToList();
                    if (CourseAssignments.Count() == 0)
                    {
                        ConsoleUI.ShowLine("->this course has not assignments\n");
                    }
                    else
                    {
                        foreach (Assignment a in CourseAssignments)
                        {
                            ConsoleUI.ShowMessage("->");
                            ConsoleUI.ShowLine(a);
                        }
                        ConsoleUI.ChangeLine();
                    }
                }
            }

            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Exemple #3
0
        public void Delete()
        {
            bool exit;

            ICollection <Course>     courses     = DBAssignmentsPerCourse.ReadCoursesWithAssignments();
            ICollection <Assignment> assignments = DBAssignmentsPerCourse.ReadAssignmentsWithCourses();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("No courses yet");
            }
            else
            {
                ConsoleUI.ShowLine("List of courses with assignments\n");
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);

                    ICollection <Assignment> CourseAssignments = c.Assignments.ToList();
                    if (CourseAssignments.Count() == 0)
                    {
                        ConsoleUI.ShowLine("->this course has not assignments\n");
                    }
                    else
                    {
                        foreach (Assignment a in CourseAssignments)
                        {
                            ConsoleUI.ShowMessage("->");
                            ConsoleUI.ShowLine(a);
                        }
                        ConsoleUI.ChangeLine();
                    }
                }
            }

            ConsoleUI.ChangeLine();

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

            exit = ConsoleUI.GetInt(out int selectedAssignment, "give assignment id to disconnect: ");
            if (exit)
            {
                return;
            }

            Assignment assignment;

            try
            {
                assignment = assignments.Where(a => a.Id == selectedAssignment).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO ASSIGNMENT FOUND FOR ID {selectedAssignment}");
                ConsoleUI.ReadKey();
                return;
            }

            exit = ConsoleUI.GetInt(out int selectedCourse, "give course id to disconnect: ");
            if (exit)
            {
                return;
            }

            Course course;

            try
            {
                course = courses.Where(c => c.Id == selectedCourse).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO COURSE FOUND FOR ID {selectedCourse}");
                ConsoleUI.ReadKey();
                return;
            }

            bool courseHasNoAssignment = course.Assignments.Where(a => a.Id == selectedAssignment).Count() == 0;

            if (courseHasNoAssignment)
            {
                ConsoleUI.ShowLine("this course doesn't connect to this assignment");
                //ConsoleUI.ReadKey();
                //return;
            }

            bool assignmentHasNoCourse = assignment.Courses.Where(c => c.Id == selectedCourse).Count() == 0;

            if (assignmentHasNoCourse)
            {
                ConsoleUI.ShowLine("this assigment doesn't connect to this course");
                ConsoleUI.ReadKey();
                return;
            }

            int result = DBAssignmentsPerCourse.DeleteAssignmentPerCourse(selectedAssignment, selectedCourse);

            if (result == 0)
            {
                ConsoleUI.ShowLine("connection could NOT be removed");
            }
            else
            {
                ConsoleUI.ShowLine("connection removed");
                AssignmentPerStudentManager apsm = new AssignmentPerStudentManager();
                apsm.DeleteByAssignment(selectedAssignment, selectedCourse);
            }
        }
Exemple #4
0
        public void Create()
        {
            bool exit;

            ConsoleUI.ShowLine("Assignments");
            ICollection <Assignment> assignments = DBAssignmentsPerCourse.ReadAssignmentsWithCourses();

            if (assignments.Count() == 0)
            {
                ConsoleUI.ShowLine("no assignment yet");
            }
            else
            {
                foreach (Assignment a in assignments)
                {
                    ConsoleUI.ShowLine(a);
                }
            }

            ConsoleUI.ChangeLine();

            ConsoleUI.ShowLine("Courses");
            ICollection <Course> courses = DBAssignmentsPerCourse.ReadCoursesWithAssignments();

            if (courses.Count() == 0)
            {
                ConsoleUI.ShowLine("no courses yet");
            }
            else
            {
                foreach (Course c in courses)
                {
                    ConsoleUI.ShowLine(c);
                }
            }

            ConsoleUI.ChangeLine();

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

            exit = ConsoleUI.GetInt(out int selectedAssignment, "give assignment id to connect: ");
            if (exit)
            {
                return;
            }

            Assignment assignment;

            try
            {
                assignment = assignments.Where(a => a.Id == selectedAssignment).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO ASSIGNMENT FOUND FOR ID {selectedAssignment}");
                ConsoleUI.ReadKey();
                return;
            }

            exit = ConsoleUI.GetInt(out int selectedCourse, "give course id to connect: ");
            if (exit)
            {
                return;
            }

            Course course;

            try
            {
                course = courses.Where(c => c.Id == selectedCourse).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO COURSE FOUND FOR ID {selectedCourse}");
                ConsoleUI.ReadKey();
                return;
            }

            bool courseHasAssignment = course.Assignments.Where(a => a.Id == selectedAssignment).Count() > 0;

            if (courseHasAssignment)
            {
                ConsoleUI.ShowLine("this course already connects to this assigment");
                //ConsoleUI.ReadKey();
                //return;
            }

            bool assignmentHasCourse = assignment.Courses.Where(c => c.Id == selectedCourse).Count() > 0;

            if (assignmentHasCourse)
            {
                ConsoleUI.ShowLine("this assignment already connects to this course");
                ConsoleUI.ReadKey();
                return;
            }

            int result = DBAssignmentsPerCourse.CreateAssignmentPerCourse(selectedAssignment, selectedCourse);

            if (result == 0)
            {
                ConsoleUI.ShowLine("connection could NOT be made");
            }
            else
            {
                ConsoleUI.ShowLine("connection saved");
                //add assignment to students of this course
                AssignmentPerStudentManager apsm = new AssignmentPerStudentManager();
                apsm.CreateFromNewAssignment(selectedAssignment, selectedCourse);
                ConsoleUI.ReadKey();
            }
        }
Exemple #5
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");
        }