Beispiel #1
0
 public static void RelateCoursesToTrainers()
 {
     using (MyContext db = new MyContext())
     {
         Console.WriteLine("Please add Course to the Trainer using the ID's from the lists");
         GetAllTrainers();
         CourseManager.GetAllCourses();
         Console.Write("Select the Trainer id from the list you want to add a course: ");
         int id_t = Convert.ToInt32(Console.ReadLine());
         Console.Write("Select the Course id from the list you want to add to the Trainer: ");
         int     id_c = Convert.ToInt32(Console.ReadLine());
         Trainer T    = new Trainer();
         Trainer T1   = db.Trainers.Find(id_t);
         Course  C    = new Course();
         Course  C1   = db.Courses.Find(id_c);
         T1.Courses.Add(C1);
         db.SaveChanges();
         Console.WriteLine("\nCourse successfully submitted to the trainer");
     }
 }
        public static void RelateStudentsCourses()
        {
            using (MyContext db = new MyContext())
            {
                GetAllStudents();
                CourseManager.GetAllCourses();
                Console.WriteLine("Please relate the students and the courses using their ID's");
                Console.Write("Select a course id from the course list: ");
                int    id_C = Convert.ToInt32(Console.ReadLine());
                Course C    = new Course();
                Course C1   = db.Courses.Find(id_C);

                Student S = new Student();
                Console.Write("Select a Student id from the students list: ");
                int     id_s = Convert.ToInt32(Console.ReadLine());
                Student S1   = db.Students.Find(id_s);
                S1.Courses.Add(C1);
                db.SaveChanges();
                Console.WriteLine("Input has been successfully submitted\n");
            }
        }