public static void Main()
        {
            var db = new StudentSystemDBContext();

            string[] courses = new string[5] { "Biology", "Chemistry", "Physics", "Maths", "Astronomy"};
            string[] studentFirstNames = new string[5] {"Ivan", "Gancho", "Stavri", "Jechko", "Asparuh"};
            string[] studentLastNames = new string[5] {"Ivanov", "Ganchov", "Stavrov", "Jechkov", "Asparuhov"};

            for (int i = 0; i < 5; i++)
            {
                var course = new Courses
                {
                    Name = courses[i],
                };

                var student = new Student
                {
                    FirstName = studentFirstNames[i],
                    LastName = studentLastNames[i],
                    Age = 20 + i,
                    ContactInfo = new StudentContactInfo
                    {
                        Skype = studentFirstNames[i] + i,
                        Email = studentFirstNames[i] + "@gmail.com",
                        Facebook = studentFirstNames[i] + "_" + studentLastNames[i] + "@facebook.com"
                    },
                    Courses = { course },
                    StudentStatus = i % 2 == 0 ? StudentStatus.Online : StudentStatus.Onsite,
                    Homeworks = new HashSet<Homework> 
                    {
                        new Homework
                        {
                            Content = "Homework" + i,
                            CoursesId = i + 1
                        }
                    },
                };

                db.Students.Add(student);
            }

            db.SaveChanges();

            db.Students.Where(s => s.FirstName == "Jechko").First().Assistant = db.Students.Where(s => s.FirstName == "Asparuh").First();

            db.Courses.Add(new Courses
            {
                Name = "NewCourse",
                Description = "NewCourseInserted",
                Materials = "Materials For the New Course"
            });
            db.SaveChanges();

            foreach (var student in db.Students.ToArray())
            {
                Console.Write("FirstName - {0}, LastName - {1}, Age - {2}, Facebook - {3}", 
                    student.FirstName, student.LastName, student.Age, student.ContactInfo.Facebook);
                if (student.Homeworks.Count() != 0)
                {
                    foreach (var homework in student.Homeworks)
                    {
                        Console.Write(", Homework - {0}", homework.Content);
                    }
                }

                if (student.Courses.Count() != 0)
                {
                    foreach (var course in student.Courses)
                    {
                        Console.Write(", Course - {0}", course.Name);
                    }
                }
                
                Console.WriteLine();
                Console.WriteLine("-----------------------------------------");
            }
        }
Exemple #2
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemDBContext, Configuration>());

            var db = new StudentSystemDBContext();

            var studentsWithSubmissions = from h in db.Homeworks
                                          from s in db.Students
                                          where s.Id == h.SubmissionStudent.Id
                                          select s.Name + " " + h.Content;
            foreach (var item in studentsWithSubmissions.ToList())
            {
                Console.WriteLine(item.ToString());
            }

            db.Courses.ToList().ForEach(c => c.Resources.ToList().ForEach(r => Console.WriteLine(c.Name + " " + r.Name)));

            Course courseOne = new Course()
            {
                Name = "Guga Buga Course",
                StartDate = new DateTime(2222, 3, 1),
                Price = 354
            };

            Resource resourceVideo = new Resource()
            {
                Name = "Video resource",
                TypeOfResource = ResourceType.Video,
                Link = "The Link"
            };
            Resource resourceDocs = new Resource()
            {
                Name = "Docs resource",
                TypeOfResource = ResourceType.Document,
                Link = "The Link"
            };
            Resource resourceOther = new Resource()
            {
                Name = "Other resource",
                TypeOfResource = ResourceType.Other,
                Link = "The Link"
            };
            courseOne.Resources.Add(resourceDocs);
            courseOne.Resources.Add(resourceOther);
            courseOne.Resources.Add(resourceVideo);

            Student student = new Student()
            {
                Name = "Gargandiua",
                BirthDay = new DateTime(1835, 1, 1),
                RegistrationDate = new DateTime(2020, 3, 3)
            };
            student.Courses.Add(courseOne);

            Resource resourceNew = new Resource()
            {
                Name = "The New RECOURCE",
                Link = "The New Link",
                TypeOfResource = ResourceType.Presentation
            };

            db.Courses.Add(courseOne);
            db.Students.Add(student);
            db.Resources.Add(resourceDocs);
            db.Resources.Add(resourceNew);
            db.Resources.Add(resourceOther);
            db.Resources.Add(resourceVideo);
            db.SaveChanges();
        }