Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Title = "My School";
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            Console.ForegroundColor = ConsoleColor.Black;
            using (SchoolContext db = new SchoolContext())
            {
                if (UserManager.getCountOfUsers() < 1)
                {
                    UserManager.CreateUser("admin", SecurePasswordHasher.Hash("admin"));
                }
            }
            Console.WriteLine("You want to login in as a Student(1), Trainer(2) or Head Master(3)?");
            string ch = Console.ReadLine();

            while (true)
            {
                if (ch == "3")
                {
                    Menu.MainMenuHeadMaster();
                }
                else if (ch == "2")
                {
                    Menu.MainMenuTrainer();
                }
                else if (ch == "1")
                {
                    Menu.MainMenuStudent();
                }
                else
                {
                    Console.WriteLine("Invalid input. Choose between 1,2 or 3.");
                    ch = Console.ReadLine();
                }
            }
        }
Ejemplo n.º 2
0
        public static void MainMenuHeadMaster()
        {
            User user  = new User();
            bool login = false;

            while (true)
            {
                while (login == false)
                {
                    Console.Write("Username: "******"Password: "******"\nError: Username and Password do not match\n");
                    }
                    else if (SecurePasswordHasher.Verify(password, user.Password) == true)
                    {
                        Console.WriteLine("Successfull login\n");
                        login = true;
                    }
                    else
                    {
                        Console.WriteLine("\nError: Username and Password do not match\n");
                    }
                }



                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("Menu");
                    Console.WriteLine("1. Add a Student");
                    Console.WriteLine("2. See all Students");
                    Console.WriteLine("3. Update Student");
                    Console.WriteLine("4. Delete Student");
                    Console.WriteLine("5. Create a Course");
                    Console.WriteLine("6. See all Courses");
                    Console.WriteLine("7. Update a Course");
                    Console.WriteLine("8. Delete a Course");
                    Console.WriteLine("9. Create an Assignment");
                    Console.WriteLine("10. See all Assignments");
                    Console.WriteLine("11. Update an Assignment");
                    Console.WriteLine("12. Delete an Assignment");
                    Console.WriteLine("13. Create a Trainer");
                    Console.WriteLine("14. See all Trainers");
                    Console.WriteLine("15. Update a Trainer");
                    Console.WriteLine("16. Delete a Trainer");
                    Console.WriteLine("17. Add a student in a Course");
                    Console.WriteLine("18. See all Students per Course or Courses per Student");
                    Console.WriteLine("19. Update a Student in a Course");
                    Console.WriteLine("20. Delete a Student from a Course");
                    Console.WriteLine("21. Add a Trainer in a Course");
                    Console.WriteLine("22. See all Trainers per Course");
                    Console.WriteLine("23. Update a Trainer per Course");
                    Console.WriteLine("24. Delete a Trainer per Course");
                    Console.WriteLine("25. Add an Assignment for a Course");
                    Console.WriteLine("26. See all Assignments per Course");
                    Console.WriteLine("27. Update an Assignment per Course");
                    Console.WriteLine("28. Delete an Assignment for a Course");
                    Console.WriteLine("29. Create a Schedule per Course");
                    Console.WriteLine("30. See a Schedule per Course");
                    Console.WriteLine("30. Update a Schedule per Course");
                    Console.WriteLine("31. Delete a Schedule from a Course");
                    Console.WriteLine("0. Exit");

                    string choise = Console.ReadLine();
                    switch (choise)
                    {
                    case "1":
                    {
                        Console.Clear();
                        Console.Write("Insert Student's Username: "******"Password: "******"First name: ");
                        string firstName = Console.ReadLine();
                        Console.Write("Last name: ");
                        string lastName = Console.ReadLine();
                        Console.Write("Date of birth: ");
                        DateTime dateOfBirth = Convert.ToDateTime(Console.ReadLine()).Date;
                        Console.Write("Tuition Fees: ");
                        decimal tuitionFees = Convert.ToDecimal(Console.ReadLine());
                        StudentManager.CreateStudent(username, hashedPass, firstName, lastName, dateOfBirth, tuitionFees);
                        Console.Clear();
                        break;
                    }

                    case "2":
                    {
                        Console.Clear();
                        foreach (var student in StudentManager.GetAllStudents())
                        {
                            Console.WriteLine(student);
                        }
                        Console.ReadLine();

                        break;
                    }

                    case "3":
                    {
                        Console.Clear();
                        foreach (var student in StudentManager.GetAllStudents())
                        {
                            Console.WriteLine(student);
                        }
                        Console.Write("Choose a Student to update(id): ");
                        int oldStudentID = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Insert the new first name: ");
                        string firstName = Console.ReadLine();
                        Console.Write("Insert the new last name: ");
                        string lastName = Console.ReadLine();
                        Console.Write("insert the date of birth: ");
                        DateTime dateOfBirth = Convert.ToDateTime(Console.ReadLine()).Date;
                        Console.Write("Insert the new tuition fees: ");
                        decimal tuitionFees = Convert.ToDecimal(Console.ReadLine());
                        StudentManager.UpdateStudent(oldStudentID, firstName, lastName, dateOfBirth, tuitionFees);
                        break;
                    }

                    case "4":
                    {
                        Console.Clear();
                        foreach (var student in StudentManager.GetAllStudents())
                        {
                            Console.WriteLine(student);
                        }
                        Console.Write("Give Student id to delete: ");
                        int id = Convert.ToInt32(Console.ReadLine());
                        StudentManager.DeleteStudent(id);

                        break;
                    }

                    case "5":
                    {
                        Console.Clear();
                        Console.Write("Course title: ");
                        string title = Console.ReadLine();
                        Console.Write("Course's stream(Java/C#)");
                        string stream = Console.ReadLine();
                        Console.Write("Courses's type(Full/Part)");
                        string type = Console.ReadLine();
                        Console.Write("Start Date: ");
                        DateTime startDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        Console.Write("End Date: ");
                        DateTime endDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        CourseManager.CreateCourse(title, stream, type, startDate, endDate);
                        Console.Clear();
                        break;
                    }

                    case "6":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.ReadLine();
                        break;
                    }

                    case "7":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Insert id of course to change: ");
                        int oldId = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Insert new title");
                        string title = Console.ReadLine();
                        Console.Write("change the stream: ");
                        string stream = Console.ReadLine();
                        Console.Write("Choose the new type: ");
                        string type = Console.ReadLine();
                        Console.Write("Set new Start date: ");
                        DateTime startDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        Console.Write("Set new end date: ");
                        DateTime endDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        CourseManager.UpdateCourse(oldId, title, stream, type, startDate, endDate);
                        break;
                    }

                    case "8":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Give Course id to delete: ");
                        int id = Convert.ToInt32(Console.ReadLine());
                        CourseManager.DeleteCourse(id);
                        break;
                    }

                    case "9":
                    {
                        Console.Clear();
                        Console.Write("Title: ");
                        string title = Console.ReadLine();
                        Console.Write("Description: ");
                        string description = Console.ReadLine();
                        Console.Write("Submission date: ");
                        DateTime submission = Convert.ToDateTime(Console.ReadLine()).Date;
                        AssignmentManager.CreateAssignment(title, description, submission);
                        Console.Clear();
                        break;
                    }

                    case "10":
                    {
                        Console.Clear();
                        foreach (var assignment in AssignmentManager.GetAllAssignments())
                        {
                            Console.WriteLine(assignment);
                        }
                        Console.ReadLine();
                        break;
                    }

                    case "11":
                    {
                        Console.Clear();
                        foreach (var assignment in AssignmentManager.GetAllAssignments())
                        {
                            Console.WriteLine(assignment);
                        }
                        Console.Write("Choose assignment to update(id): ");
                        int oldId = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Type new title: ");
                        string title = Console.ReadLine();
                        Console.Write("Type new description: ");
                        string description = Console.ReadLine();
                        Console.Write("insert new submission date: ");
                        DateTime submission = Convert.ToDateTime(Console.ReadLine()).Date;
                        AssignmentManager.UpdateAssignment(oldId, title, description, submission);
                        break;
                    }

                    case "12":
                    {
                        Console.Clear();
                        foreach (var assignment in AssignmentManager.GetAllAssignments())
                        {
                            Console.WriteLine(assignment);
                        }
                        Console.Write("Give assignment id to delete: ");
                        int id = Convert.ToInt32(Console.ReadLine());
                        AssignmentManager.DeleteAssignment(id);
                        break;
                    }

                    case "13":
                    {
                        Console.Write("Insert Trainer's Username: "******"Password: "******"First name: ");
                        string firstName = Console.ReadLine();
                        Console.Write("Last name: ");
                        string lastName = Console.ReadLine();
                        Console.Write("Subject: ");
                        string subject = Console.ReadLine();
                        TrainerManager.CreateTrainer(username, hashedPass, firstName, lastName, subject);
                        Console.Clear();
                        break;
                    }

                    case "14":
                    {
                        Console.Clear();
                        foreach (var trainer in TrainerManager.GetAllTrainers())
                        {
                            Console.WriteLine(trainer);
                        }
                        Console.ReadLine();
                        break;
                    }

                    case "15":
                    {
                        Console.Clear();
                        foreach (var trainer in TrainerManager.GetAllTrainers())
                        {
                            Console.WriteLine(trainer);
                        }
                        Console.Write("Choose trainer to update");
                        int oldId = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Type his new subject");
                        string subject = Console.ReadLine();
                        TrainerManager.UpdateTrainer(oldId, subject);
                        Console.ReadLine();
                        break;
                    }

                    case "16":
                    {
                        Console.Clear();
                        foreach (var trainer in TrainerManager.GetAllTrainers())
                        {
                            Console.WriteLine(trainer);
                        }
                        Console.Write("Give Trainer id to delete: ");
                        int id = Convert.ToInt32(Console.ReadLine());
                        TrainerManager.DeleteTrainer(id);
                        break;
                    }

                    case "17":
                    {
                        Console.Clear();
                        foreach (var student in StudentManager.GetAllStudents())
                        {
                            Console.WriteLine(student);
                        }
                        Console.Write("Select the id of the Student: ");
                        int studentID = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Select the id of the Course: ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        StudentCourseManager.CreateStudentCourse(studentID, courseID);
                        break;
                    }

                    case "18":
                    {
                        Console.Write("You want to see the Courses of one student(1), or the Students in a Course(2)?: ");
                        string ch = Console.ReadLine();
                        if (ch == "1")
                        {
                            Console.Clear();
                            foreach (var student in StudentManager.GetAllStudents())
                            {
                                Console.WriteLine(student);
                            }
                            Console.Write("Give the id of the student: ");
                            int studentID = Convert.ToInt32(Console.ReadLine());
                            StudentCourseManager.GetCoursesPerStudent(studentID);
                            Console.ReadLine();
                        }
                        else
                        {
                            Console.Clear();
                            foreach (var course in CourseManager.GetAllCourses())
                            {
                                Console.WriteLine(course);
                            }
                            Console.Write("Give the id of the course: ");
                            int courseID = Convert.ToInt32(Console.ReadLine());
                            StudentCourseManager.GetStudentsPerCourse(courseID);
                            Console.ReadLine();
                        }
                        break;
                    }

                    case "19":
                    {
                        Console.Clear();
                        foreach (var student in StudentManager.GetAllStudents())
                        {
                            Console.WriteLine(student);
                        }
                        Console.Write("Choose a student(id): ");
                        int studentId = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Choose the new id of the course: ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        StudentCourseManager.UpdateStudentCourse(studentId, courseID);
                        break;
                    }

                    case "20":
                    {
                        Console.Clear();
                        Console.Write("which student(id) you want to delete from a course?: ");

                        int studentID = Convert.ToInt32(Console.ReadLine());
                        Console.Write("And from which course(id)?: ");
                        StudentCourseManager.GetCoursesPerStudent(studentID);
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        StudentCourseManager.DeleteStudentPerCourse(studentID, courseID);
                        break;
                    }

                    case "21":
                    {
                        foreach (var trainer in TrainerManager.GetAllTrainers())
                        {
                            Console.WriteLine(trainer);
                        }
                        Console.Write("Choose a trainer: ");
                        int trainerId = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("choose a course to see the trainers: ");
                        int courseId = Convert.ToInt32(Console.ReadLine());
                        TrainerCourseManager.CreateTrainerCourse(trainerId, courseId);
                        break;
                    }

                    case "22":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("select the course to view trainers: ");
                        int courseId = Convert.ToInt32(Console.ReadLine());
                        TrainerCourseManager.GetTrainerPerCourse(courseId);
                        break;
                    }

                    case "23":
                    {
                        Console.Clear();
                        foreach (var trainer in TrainerManager.GetAllTrainers())
                        {
                            Console.WriteLine(trainer);
                        }
                        Console.Write("select a trainer id to update his course: ");
                        int trainerID = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Select the new course(id): ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        TrainerCourseManager.UpdateTrainerPerCourse(trainerID, courseID);
                        break;
                    }

                    case "24":
                    {
                        Console.Clear();
                        foreach (var trainer in TrainerManager.GetAllTrainers())
                        {
                            Console.WriteLine(trainer);
                        }
                        Console.Write("select a trainer id to delete from a course: ");
                        int trainerID = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Select the course(id): ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        TrainerCourseManager.DeleteTrainerPerCourse(trainerID, courseID);
                        break;
                    }

                    case "25":
                    {
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Choose a course(id): ");
                        int courseId = Convert.ToInt32(Console.ReadLine());
                        foreach (var assignment in AssignmentManager.GetAllAssignments())
                        {
                            Console.WriteLine(assignment);
                        }
                        Console.Write("choose an assignment to add to courses: ");
                        int assignmentId = Convert.ToInt32(Console.ReadLine());
                        CourseAssignmentManager.CreateCourseAssignment(courseId, assignmentId);
                        break;
                    }

                    case "26":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("select the course to view assignments: ");
                        int courseId = Convert.ToInt32(Console.ReadLine());
                        CourseAssignmentManager.GetAssignmentsPerCourse(courseId);
                        break;
                    }

                    case "27":
                    {
                        Console.Clear();
                        foreach (var assignment in AssignmentManager.GetAllAssignments())
                        {
                            Console.WriteLine(assignment);
                        }
                        Console.Write("select an assignment id to update his course: ");
                        int assignmentID = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Select the new course(id): ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        CourseAssignmentManager.UpdateAssignmentCourse(assignmentID, courseID);
                        break;
                    }

                    case "28":
                    {
                        Console.Clear();
                        foreach (var assignment in AssignmentManager.GetAllAssignments())
                        {
                            Console.WriteLine(assignment);
                        }
                        Console.Write("select an assignment id to delete from a course: ");
                        int assignmentID = Convert.ToInt32(Console.ReadLine());
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course);
                        }
                        Console.Write("Select the course(id): ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        TrainerCourseManager.DeleteTrainerPerCourse(assignmentID, courseID);
                        break;
                    }

                    case "29":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course.Id + "--" + course.Title);
                        }
                        Console.Write("Choose the Course to make the schedule(id): ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        Console.Write("When will start?: ");
                        DateTime startDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        Console.Write("When will end?: ");
                        DateTime endDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        CourseManager.CourseSchedule(courseID, startDate, endDate);
                        break;
                    }

                    case "30":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine($"Course: {course.Title} starts at {course.StartDate} and ends at {course.EndDate}");
                        }
                        break;
                    }

                    case "31":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course.Id + "--" + course.Title);
                        }
                        Console.Write("Choose the Course to update the schedule(id): ");
                        int courseID = Convert.ToInt32(Console.ReadLine());
                        Console.Write("When will start finally?: ");
                        DateTime startDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        Console.Write("And when will end?: ");
                        DateTime endDate = Convert.ToDateTime(Console.ReadLine()).Date;
                        CourseManager.CourseSchedule(courseID, startDate, endDate);
                        break;
                    }

                    case "32":
                    {
                        Console.Clear();
                        foreach (var course in CourseManager.GetAllCourses())
                        {
                            Console.WriteLine(course.Id + "--" + course.Title);
                        }
                        Console.Write("Which Cousre Schedule you want to delete?:");
                        int courseId = Convert.ToInt32(Console.ReadLine());
                        CourseManager.DeleteCourse(courseId);
                        break;
                    }

                    case "0":
                        Environment.Exit(0);
                        break;
                    }
                }
            }
        }