Esempio n. 1
0
        private static void AddCourse()
        {
            using (DBModelContainer context = new DBModelContainer())
            {
                Course c = new Course();

                Console.Write("Course Code: ");
                c.Code = Console.ReadLine();

                Console.Write("Cousre Name: ");
                c.Name = Console.ReadLine();

                context.Courses.Add(c);
                context.SaveChanges();

            }
        }
Esempio n. 2
0
        private static void AddStudent()
        {
            using (DBModelContainer context = new DBModelContainer())
            {
                Student s = new Student();

                Console.Write("Student First Name: ");
                s.FirstName = Console.ReadLine();

                Console.Write("Student Last Name: ");
                s.LastName = Console.ReadLine();

                Console.Write("Student Registration Number: ");
                s.Number = Console.ReadLine();

                context.Students.Add(s);
                context.SaveChanges();

            }
        }
Esempio n. 3
0
        private static void AddStudentToCourse()
        {
            using (DBModelContainer context = new DBModelContainer())
            {
                Console.WriteLine("Student Registration Number: ");
                string srn = Console.ReadLine();

                Student student =( from s in context.Students
                            where s.Number == srn
                            select s).FirstOrDefault();
                if (student != null)
                {
                    DisplayStudent(student);

                    Console.WriteLine("Course Code: ");
                    string cc = Console.ReadLine();

                    Course course = (from c in context.Courses
                                       where c.Code == cc
                                       select c).FirstOrDefault();
                    if(course !=null)
                    {
                        DisplayCourse(course);

                        student.Courses.Add(course);
                        context.SaveChanges();
                    }
                    else
                    {
                        Console.WriteLine("Invalid Course Code.");
                    }

                }
                else
                {
                    Console.WriteLine("Invalid Student Registration Number.");
                }

            }
        }
Esempio n. 4
0
        private static void DisplayAllCourses()
        {
            using (DBModelContainer context = new DBModelContainer())
            {
                var query = from c in context.Courses
                            select c;

                foreach (Course course in query)
                {
                    DisplayCourse(course);
                    foreach (Student student in course.Students)
                    {
                        DisplayStudent(student);
                    }
                }
            }
        }
Esempio n. 5
0
        private static void DisplayAllStudents()
        {
            using (DBModelContainer context = new DBModelContainer())
            {
                var query = from s in context.Students
                            select s;

                //List<Student> students = new List<Student>();
                //students = query.ToList();

                foreach (Student student in query)
                {
                    DisplayStudent(student);

                    foreach (Course course in student.Courses)
                    {
                        DisplayCourse(course);
                    }
                }

            }
        }