// In order to enable migrations set <Project>.Data as current project
        // Enter in Package Manager Console PM> Enable-Migrations -EnableAutomaticMigrations
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemEntities, Configuration>());

            Console.WriteLine("Creating Database \"StudentSystem\"");
            var ctx = new StudentSystemEntities();
            ctx.Homeworks.Add(new Homework { Content = "First Homework", TimeSent = DateTime.Now });
            ctx.SaveChanges();
        }
Exemplo n.º 2
0
        private static Student AddStudent(StudentSystemEntities context, string name, ICollection<Course> courses = null)
        {
            var newStudent = new Student()
            {
                Name = name,
            };

            if (courses != null)
            {
                newStudent.Courses = courses;
            }

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

            return newStudent;
        }
Exemplo n.º 3
0
        private static void AddHomework(StudentSystemEntities context, string content, DateTime sentDate, Course course, Student student)
        {
            var newHomework = new Homework()
            {
                Content = content,
                TimeSent = sentDate,
                Course = course,
                Student = student
            };

            course.Homeworks.Add(newHomework);
            student.Homeworks.Add(newHomework);
            context.Homeworks.Add(newHomework);
            context.SaveChanges();
        }
Exemplo n.º 4
0
        private static Course AddCourse(
            StudentSystemEntities context,
            string name,
            string description = null,
            string materials = null,
            ICollection<Student> students = null)
        {
            var newCourse = new Course()
            {
                Name = name,
                Description = description,
                Materials = materials
            };

            if (students != null)
            {
                newCourse.Students = students;  
            }

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

            return newCourse;
        }