Exemple #1
0
 //f.	A method to remove all course registrations for all students in the database
 public static void removeCourseRegistrations()
 {
     Console.WriteLine("removeCourseRegistration() invoked.");
     using (var db = new Winter2015Lab1DBEntities())
     {
         var q = from c in db.Courses
                 select c;
         foreach (Course course in q)
         {
             course.Students.Clear();
         }
     }
 }
Exemple #2
0
        //c.	A method to display all course registrations for all students to the console.  This method should display course names, course codes and student names
        public static void displayCourseRegistration()
        {
            Console.WriteLine("displayCourseRegistration() invoked.");
            using (var db = new Winter2015Lab1DBEntities())
            {
                var q = from c in db.Courses
                        select c;

                foreach (Course course in q)
                {
                    Console.WriteLine("{0} - {1}", course.courseCode, course.courseName);
                }
            }
        }
Exemple #3
0
        //e.	A method to display all students who are registered for a particular course on the console based on a course parameter.  This method should display course names, course codes and student names
        public static void allStudentsOneCourse(String courseCode)
        {
            Console.WriteLine("allStudentsOneCourse(String courseCode) invoked.");
            using (var db = new Winter2015Lab1DBEntities())
            {
                Course cou = (from c in db.Courses
                              where c.courseCode == courseCode
                              select c).First();
                Console.WriteLine("{0} - {1}", cou.courseCode, cou.courseName);

                foreach (Student student in cou.Students)
                {
                    Console.WriteLine("\t\t{0} {1}", student.firstName, student.lastName);
                }
            }
        }
Exemple #4
0
        //d.	A method to display all course registrations for one student to the console based on a student number parameter.  This method should display course names, course codes and student names
        public static void allCoursesOneStudent(String studentNum)
        {
            Console.WriteLine("allCoursesOneStudent(String studentNum) invoked.");
            using (var db = new Winter2015Lab1DBEntities())
            {
                Student stu = (from s in db.Students
                               where s.StudentNum == studentNum
                               select s).First();
                Console.WriteLine("{0} - {1} {2}", stu.StudentNum, stu.firstName, stu.lastName);

                foreach (Course course in stu.Courses)
                {
                    Console.WriteLine("\t\t{0} - {1}", course.courseCode, course.courseName);
                }
            }
        }
Exemple #5
0
        //a.	A method to add a new course registration with parameters for the student number and course code
        public static void addCourseRegistration(String studentNum, string courseCode)
        {
            Console.WriteLine("addCourseRegistration() invoked.");
            using (var db = new Winter2015Lab1DBEntities())
            {
                Student stu = (from s in db.Students
                               where s.StudentNum == studentNum
                               select s).First();
                Course cou = (from c in db.Courses
                              where c.courseCode == courseCode
                              select c).First();

                cou.Students.Add(stu);
                db.SaveChanges();
            }
        }