Ejemplo n.º 1
0
        public static void Create(CourseEnrollmentContext courseEnrollmentContext)
        {
            StudentOperation.Retrieve(courseEnrollmentContext);

            CourseOperation.Retrieve(courseEnrollmentContext);

            Console.Write("\nStudent ID:");
            var studentID = Convert.ToInt16(Console.ReadLine());
            var student   = courseEnrollmentContext.Students.FirstOrDefault(p => p.StudentID == studentID);



            Console.Write("\nCourse ID:");
            var courseID = Convert.ToInt16(Console.ReadLine());
            var course   = courseEnrollmentContext.Courses.FirstOrDefault(p => p.CourseID == courseID);

            if (course != null && student != null)
            {
                courseEnrollmentContext.Enrollments.Add(new Enrollment()
                {
                    Course = course, Student = student
                });
                courseEnrollmentContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public static void TestUpdateOpertaion()
        {
            /// update : Changing John Travelta -> to Kevin Travelta
            var students = courseEnrollmentContext.Students.ToList();
            var student  = students.FirstOrDefault(p => p.FirstMidName == "John" && p.LastName == "Travelta");

            if (student != null)
            {
                student.FirstMidName = "Kevin";
            }

            courseEnrollmentContext.SaveChanges();

            Console.WriteLine("\n*******  Students List after Changing ************");
            StudentOperation.Retrieve(courseEnrollmentContext);

            Console.WriteLine("\n*******  Enrolment List after Changing ************");
            EnrollmentOperation.Retrieve(courseEnrollmentContext);
        }
Ejemplo n.º 3
0
        public static void PopulateDatabase()
        {
            if (courseEnrollmentContext.Enrollments.Count() == 0)
            {
                Course course1 = new Course()
                {
                    Title = "Adv C#", Credits = 4
                };
                Course course2 = new Course()
                {
                    Title = "React/Redux", Credits = 3
                };
                Course course3 = new Course()
                {
                    Title = "Angular", Credits = 3
                };

                Student st1 = new Student()
                {
                    FirstMidName = "John", LastName = "Travelta", EnrollmentDate = DateTime.Now
                };
                Student st2 = new Student()
                {
                    FirstMidName = "Robert", LastName = "Deniro", EnrollmentDate = DateTime.Now
                };
                Student st3 = new Student()
                {
                    FirstMidName = "Will", LastName = "Smith", EnrollmentDate = DateTime.Now
                };

                Enrollment en1 = new Enrollment()
                {
                    Course = course1, Student = st1
                };
                Enrollment en2 = new Enrollment()
                {
                    Course = course1, Student = st2
                };
                Enrollment en3 = new Enrollment()
                {
                    Course = course2, Student = st3
                };
                Enrollment en4 = new Enrollment()
                {
                    Course = course3, Student = st2
                };
                Enrollment en5 = new Enrollment()
                {
                    Course = course2, Student = st1
                };

                courseEnrollmentContext.Enrollments.Add(en1);
                courseEnrollmentContext.Enrollments.Add(en2);
                courseEnrollmentContext.Enrollments.Add(en3);
                courseEnrollmentContext.Enrollments.Add(en4);
                courseEnrollmentContext.Enrollments.Add(en5);

                courseEnrollmentContext.SaveChanges();
                Console.WriteLine("\nDatabase populated successfully.");
            }
            Console.WriteLine("\n*******  Initial Students List ************");
            StudentOperation.Retrieve(courseEnrollmentContext);

            Console.WriteLine("\n*******  Initial Course List ************");
            CourseOperation.Retrieve(courseEnrollmentContext);

            Console.WriteLine("\n*******  Initial Enrolment List ************");
            EnrollmentOperation.Retrieve(courseEnrollmentContext);
        }