Пример #1
0
        // Build to restore the packages and change the connection-strings in all projects if you're not using SSMS 2014.
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentSystemDbContext, Configuration>());

            var dbContext = new StudentSystemDbContext();
            var student   = new Students
            {
                Number   = 404,
                LastName = "Oxfordion"
            };

            dbContext.Students.Add(student);
            dbContext.SaveChanges();

            var allCourses = dbContext.Courses.ToList();

            for (int i = 0; i < 5; i++)
            {
                student.Courses.Add(allCourses[i]);
            }

            dbContext.SaveChanges();

            var studentCoursesNames = student.Courses.Select(c => c.Name);

            Console.WriteLine($"\nStudent 404's list of courses:\n-- {string.Join("\n-- ", studentCoursesNames)}");
            Console.WriteLine("\nData was inserted through the Seed method and can be checked in SSMS. :)");
        }
Пример #2
0
        public IHttpActionResult PutCourse(Guid id, Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != course.Id)
            {
                return(BadRequest());
            }

            db.Entry(course).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutTest(int id, Test test)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != test.Id)
            {
                return(BadRequest());
            }

            db.Entry(test).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "ID,YearOFStudy,Inspector,OKS,Name")] Specialty specialty)
        {
            if (ModelState.IsValid)
            {
                db.Specialties.Add(specialty);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(specialty));
        }
Пример #5
0
        // POST api/Tests
        public IHttpActionResult Post([FromBody] Test value)
        {
            var test = new Test
            {
                CourseId = value.CourseId
            };

            testsRepository.Add(value);
            data.SaveChanges();
            return(this.StatusCode(HttpStatusCode.Created));
        }
        public ActionResult Create([Bind(Include = "ID,AlpaCode,LastName,EGN,Email,Name")] Inspector inspector)
        {
            if (ModelState.IsValid)
            {
                db.Inspectors.Add(inspector);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(inspector));
        }
        public ActionResult Create([Bind(Include = "ID,Facuktetnumber,Forms,Course,Groups,Inspector,OKS,Inmage,LastName,EGN,Email,Name")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
Пример #8
0
        public ActionResult Create([Bind(Include = "ID,Name")] Facultet facultet)
        {
            if (ModelState.IsValid)
            {
                db.Facultets.Add(facultet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(facultet));
        }
        public ActionResult Create([Bind(Include = "ID,Kabinet,Modile,LastName,EGN,Email,Name")] Lecture lecture)
        {
            if (ModelState.IsValid)
            {
                db.Lecturs.Add(lecture);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(lecture));
        }
Пример #10
0
        public ActionResult Create([Bind(Include = "ID,Password,UserName,LastName,Email,Birthday,Gender,Mobile,Name")] SingIn singIn)
        {
            if (ModelState.IsValid)
            {
                db.SingIns.Add(singIn);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(singIn));
        }
Пример #11
0
        // POST api/Students
        public IHttpActionResult Post([FromBody] Student value)
        {
            var student = new Student
            {
                FirstName = value.FirstName,
                LastName  = value.LastName
            };

            studentsRepository.Add(student);
            data.SaveChanges();
            return(this.StatusCode(HttpStatusCode.Created));
        }
Пример #12
0
        // POST api/Homeworks
        public IHttpActionResult Post([FromBody] Homework value)
        {
            var test = new Homework
            {
                FileUrl  = value.FileUrl,
                TimeSent = value.TimeSent,
                Student  = value.Student,
                Course   = value.Course
            };

            homeworksRepository.Add(value);
            data.SaveChanges();
            return(this.StatusCode(HttpStatusCode.Created));
        }
Пример #13
0
        private static void SeedLicences(StudentSystemDbContext db)
        {
            var random = new Random();

            var resourseIds = db
                              .Resources
                              .Select(r => r.Id)
                              .ToList();

            for (int i = 0; i < resourseIds.Count; i++)
            {
                var totalLicesces = random.Next(1, 4);

                for (int j = 0; j < totalLicesces; j++)
                {
                    db.Licenses.Add(new License
                    {
                        Name       = $"License {i} {j}",
                        ResourceId = resourseIds[i]
                    });
                }
            }

            db.SaveChanges();
        }
        public void SaveStudentMarks(IList <TeacherStudentServiceModel> students, int courseId)
        {
            using (var data = new StudentSystemDbContext())
            {
                bool isValid = ValidateStudentsMark(students);

                if (!isValid)
                {
                    throw new InvalidOperationException(INVALID_STUDENT_MARK);
                }

                var exportData = data.StudentCourses
                                 .Where(x => x.CourseId == courseId)
                                 .ToArray();

                for (int i = 0; i < exportData.Length; i++)
                {
                    var mark = students[i].Mark;

                    if (mark != null)
                    {
                        exportData[i].Mark = Math.Round((double)mark, 2, MidpointRounding.ToEven);
                    }
                }

                data.SaveChanges();
            }
        }
Пример #15
0
        private static void AddsNewCourse()
        {
            var db     = new StudentSystemDbContext();
            var course = new Course()
            {
                Name        = "C# Basics",
                Description = "Basics course for begginer developers.",
                StartDate   = DateTime.Now,
                EndDate     = new DateTime(2015, 5, 1),
                Price       = 199.99M
            };

            var resource = new Resource()
            {
                Name           = "C Sharp",
                Link           = "www.youtube.com",
                TypeOfResource = ResourceType.Video,
                Courses        = new List <Course>()
                {
                    course
                }
            };

            using (db)
            {
                db.Courses.Add(course);
                db.Resources.Add(resource);
                db.SaveChanges();

                Console.WriteLine("Course '{0}'/resource '{1}' were added to base!", course.Name, resource.Name);
            }
        }
Пример #16
0
        public static void Seed(StudentSystemDbContext data, int amount = 30)
        {
            var amountOfMaterials = RandomGenerator.GetNumber(2, 4);
            var materials         = data.Materials.OrderBy(x => Guid.NewGuid());
            var materialsCount    = materials.Count();

            Console.WriteLine("Importing courses...");
            for (int i = 0; i < amount; i++)
            {
                var course = new Course
                {
                    Description = RandomGenerator.GetString(10, 100),
                    Name        = RandomGenerator.GetString(5, 25),
                };

                for (int j = 0; j < amountOfMaterials; j++)
                {
                    var toSkip = RandomGenerator.GetNumber(0, materialsCount - 1);
                    course.Materials.Add(materials.Skip(toSkip).Take(1).First());
                }

                data.Courses.Add(course);
            }

            data.SaveChanges();
        }
        private static void SeedStudents(StudentSystemDbContext context)
        {
            if (context.Students.Count() == 0)
            {
                var students = new Student[]
                {
                    new Student()
                    {
                        Name         = new PersonName("Ivan", "Petrov"),
                        Birthday     = new DateTime(1989, 5, 24),
                        PhoneNumber  = "8948586872",
                        RegisteredOn = DateTime.Now
                    },

                    new Student()
                    {
                        Name         = new PersonName("Petar", "Ivanov"),
                        Birthday     = new DateTime(1990, 6, 18),
                        PhoneNumber  = "08948586811",
                        RegisteredOn = DateTime.Now
                    },

                    new Student()
                    {
                        Name         = new PersonName("Chocho", "Chochev"),
                        Birthday     = new DateTime(1986, 12, 25),
                        PhoneNumber  = "08858586900",
                        RegisteredOn = DateTime.Now
                    }
                };

                context.Students.AddRange(students);
                context.SaveChanges();
            }
        }
Пример #18
0
        public static void AddHomeworks(int homeworksCount, StudentSystemDbContext dbContext)
        {
            var coursesIds = dbContext.Courses
                             .Select(c => c.Id)
                             .ToList();
            int coursesIdsCount = coursesIds.Count;

            var studentsIds = dbContext.Students
                              .Select(s => s.Id)
                              .ToList();

            int studentIdsCount = studentsIds.Count;

            for (int i = 0; i < homeworksCount; i++)
            {
                var hw = new Homework();
                hw.Content  = RandomGenerator.GenerateString(1, 2000);
                hw.TimeSent = RandomGenerator.GenarateDateInPast();

                int courseIndex = RandomGenerator.GenerateIntenger(0, coursesIdsCount - 1);
                hw.CourseId = coursesIds[courseIndex];

                int studentIndex = RandomGenerator.GenerateIntenger(0, studentIdsCount - 1);
                hw.StudentId = studentsIds[studentIndex];

                dbContext.Homeworks.Add(hw);
            }

            dbContext.SaveChanges();
        }
Пример #19
0
        private static void AddResources(StudentSystemDbContext db, int numberOfResources = 100)
        {
            var courseIds = db.Courses
                            .Select(c => c.Id)
                            .ToList();
            int resourcesPerCourse = numberOfResources / courseIds.Count;
            int enumCount          = Enum.GetValues(typeof(ResourceType)).Length;

            for (int i = 0; i < courseIds.Count; i++)
            {
                for (int j = 0; j < resourcesPerCourse; j++)
                {
                    Resource newResource = new Resource()
                    {
                        Name         = $"Resource {j} for Course {i}",
                        ResourceType = (ResourceType)random.Next(0, enumCount),
                        Url          = $"Fake Url {i}{j}",
                        CourseId     = courseIds[i]
                    };

                    db.Resources.Add(newResource);
                }
            }

            db.SaveChanges();
        }
Пример #20
0
        private static void AddHomeworkSubmissions(StudentSystemDbContext db)
        {
            var studentIds = db.Students.Select(s => s.Id).ToList();
            int enumCount  = Enum.GetValues(typeof(ResourceType)).Length;

            for (int i = 0; i < studentIds.Count; i++)
            {
                var courses = db.Students
                              .FirstOrDefault(s => s.Id == studentIds[i])
                              .Courses
                              .Select(c => c.CourseId)
                              .ToList();
                for (int j = 0; j < courses.Count; j++)
                {
                    Homework newHomework = new Homework()
                    {
                        Content        = $"By Student No. {studentIds[i]} for Course {courses[j]}",
                        ContentType    = (ContentType)random.Next(0, enumCount),
                        SubmissionDate = DateTime.Now.AddDays(i - j),
                        CourseId       = courses[j],
                        StudentId      = studentIds[i]
                    };

                    db.HomeworkSubmissions.Add(newHomework);
                }
            }

            db.SaveChanges();
        }
Пример #21
0
        private static void SeedLicenses(StudentSystemDbContext db)
        {
            int totalResourcesCount = 68;
            var resources           = db.Resources.ToList();
            var licensesAdded       = new List <License>();

            for (int i = 0; i < totalResourcesCount; i++)
            {
                int index = random.Next(0, resources.Count);
                if (resources[index].Licenses.Count != 0)
                {
                    i--;
                    continue;
                }
                int licensesCounter = random.Next(1, 5);
                for (int j = 0; j < licensesCounter; j++)
                {
                    resources[index].Licenses.Add(new License()
                    {
                        Name     = "License#_0" + j * 6,
                        Resource = resources[index]
                    });
                }
            }

            db.Licenses.AddRange(licensesAdded);
            db.SaveChanges();
        }
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentSystemDbContext, Configuration>());
            var db = new StudentSystemDbContext();

            db.Database.Initialize(true);

            var student = new Student
            {
                Age           = 30,
                FirstName     = "Ivan",
                LastName      = "Goshov",
                StudentStatus = StudentStatus.Online
            };

            student.Courses.Add(new Course
            {
                Name = "Entity Framework Rocks!"
            });

            db.Students.Add(student);
            db.SaveChanges();

            var savedStudent = db.Students.First();

            Console.WriteLine(savedStudent.Id + ": " + savedStudent.FirstName + " " + savedStudent.LastName);
        }
Пример #23
0
        private static void RelateTables(StudentSystemDbContext db)
        {
            Student student  = db.Students.Find(1);
            Course  course   = db.Courses.Find(2);
            Student student1 = db.Students.Find(3);
            Course  course1  = db.Courses.Find(1);
            Student student2 = db.Students.Find(2);
            Course  course2  = db.Courses.Find(3);


            course.Students.Add(new StudentCourses()
            {
                Student = student
            });
            course1.Students.Add(new StudentCourses()
            {
                Student = student1
            });
            course2.Students.Add(new StudentCourses()
            {
                Student = student2
            });

            student.Courses.Add(new StudentCourses()
            {
                Course = course1
            });

            student2.Courses.Add(new StudentCourses()
            {
                Course = course
            });

            db.SaveChanges();
        }
Пример #24
0
        public static void Seed(StudentSystemDbContext data, int amount = 50)
        {
            var courses      = data.Courses.OrderBy(x => Guid.NewGuid());
            var coursesCount = courses.Count();

            Console.WriteLine("Importing students...");
            for (int i = 0; i < amount; i++)
            {
                var student = new Student
                {
                    Name   = RandomGenerator.GetString(2, 50),
                    Number = RandomGenerator.GetNumber(1, 50)
                };

                var coursesPerStudent = RandomGenerator.GetNumber(2, 4);

                for (int j = 0; j < coursesPerStudent; j++)
                {
                    var toSkip = RandomGenerator.GetNumber(0, coursesCount - 1);
                    student.Courses.Add(courses.Skip(toSkip).Take(1).First());
                }

                data.Students.Add(student);
            }

            data.SaveChanges();
        }
Пример #25
0
        public static void Main()
        {
            var studentSystemDbContext = new StudentSystemDbContext();

            bool input = false;

            if (input)
            {
                for (int i = 0; i < 10; i++)
                {
                    Student  student  = SeedDAO.CreateStudent();
                    Course   course   = SeedDAO.CreateCourse();
                    Homework homework = SeedDAO.CreateHomework();
                    Resource resource = SeedDAO.CreateResourse();

                    studentSystemDbContext.Students.Add(student);
                    studentSystemDbContext.Courses.Add(course);
                    studentSystemDbContext.Homework.Add(homework);
                    studentSystemDbContext.Resources.Add(resource);
                }

                var result = studentSystemDbContext.SaveChanges();
                Console.WriteLine("Affected rows: {0}", result);
            }

            SeedDAO.DisplayStudents(studentSystemDbContext);
            SeedDAO.DisplayCourses(studentSystemDbContext);
        }
Пример #26
0
        private void SeedStudentsToCourses(StudentSystemDbContext context, List <Course> addedCourses)
        {
            Console.WriteLine("Seeding Students to Courses...");

            var studentIds = context.Students.Select(s => s.Id).ToList();

            for (int i = 0; i < TotalCourses; i++)
            {
                var currentCourse    = addedCourses[i];
                var studentsInCourse = random.Next(10, TotalStudents);

                for (int j = 0; j < studentsInCourse; j++)
                {
                    var studentId = studentIds[random.Next(0, studentIds.Count)];

                    if (!currentCourse.Students.Any(s => s.StudentId == studentId))
                    {
                        currentCourse.Students.Add(new StudentCourse {
                            StudentId = studentId
                        });
                    }
                }
            }

            context.SaveChanges();
        }
Пример #27
0
        private List <Course> SeedCourses(StudentSystemDbContext context)
        {
            Console.WriteLine("Seeding Courses...");

            var addedCourses = new List <Course>();
            var currentDate  = DateTime.Now;

            for (int i = 0; i < TotalCourses; i++)
            {
                var course = new Course
                {
                    Name        = $"Course {i + 1}",
                    Description = $"Course Details {i + 1}",
                    StartDate   = currentDate.AddDays(i),
                    EndDate     = currentDate.AddDays(random.Next(CourseDuration - 5, CourseDuration + 5)),
                    Price       = 100 + i * 10
                };

                context.Courses.Add(course);
                addedCourses.Add(course);
            }

            context.SaveChanges();

            return(addedCourses);
        }
Пример #28
0
        private void SeedResources(StudentSystemDbContext context, List <Course> addedCourses)
        {
            Console.WriteLine("Seeding Resources...");

            var resourceTypes = Enum.GetValues(typeof(ResourceType)).Cast <int>().ToArray();

            for (int i = 0; i < TotalCourses; i++)
            {
                var currentCourse     = addedCourses[i];
                var resourcesInCourse = random.Next(2, 20);

                for (int j = 0; j < resourcesInCourse; j++)
                {
                    context.Resources.Add(new Resource
                    {
                        Name         = $"Resource {currentCourse.Id}/{j + 1}",
                        URL          = $"www.softuni.bg/course{currentCourse.Id}/resource{j + 1}",
                        ResourceType = (ResourceType)resourceTypes[random.Next(0, resourceTypes.Length)],
                        Course       = currentCourse
                    });
                }
            }

            context.SaveChanges();
        }
Пример #29
0
        private void SeedHomeworks(StudentSystemDbContext context, List <Course> addedCourses)
        {
            Console.WriteLine("Seeding Homeworks...");

            var contentTypes = Enum.GetValues(typeof(ContentType)).Cast <int>().ToArray();
            var currentDate  = DateTime.Now;

            for (int i = 0; i < TotalCourses; i++)
            {
                var currentCourse    = addedCourses[i];
                var studentsInCourse = currentCourse
                                       .Students
                                       .Select(s => s.StudentId)
                                       .ToList();

                foreach (var studentId in studentsInCourse)
                {
                    var totalHomeworks = random.Next(0, 5);

                    for (int j = 0; j < totalHomeworks; j++)
                    {
                        currentCourse.HomeworkSubmissions.Add(new Homework
                        {
                            StudentId      = studentId,
                            Content        = $"Homework {currentCourse.Id}/{studentId}/{j + 1}",
                            ContentType    = (ContentType)contentTypes[random.Next(0, contentTypes.Length)],
                            SubmissionDate = currentDate.AddDays(-studentId / 10)
                        });
                    }
                }
            }

            context.SaveChanges();
        }
Пример #30
0
        private void SeedLicenses(StudentSystemDbContext context)
        {
            Console.WriteLine("Seeding Licenses...");

            var resourceIds = context
                              .Resources
                              .Select(r => r.Id)
                              .ToList();

            for (int i = 0; i < resourceIds.Count; i++)
            {
                var totalLicenses = random.Next(1, 4);

                for (int j = 0; j < totalLicenses; j++)
                {
                    context.Licenses.Add(new License
                    {
                        Name       = $"License {resourceIds[i]}/{j + 1}",
                        ResourceId = resourceIds[i]
                    });
                }

                context.SaveChanges();
            }
        }
Пример #31
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemDbContext, Configuration>());

            var db = new StudentSystemDbContext();
            var student = new Student
            {
                FirstName = "John",
                LastName = "3volta",
                FacultyNumber = "qwerty"
            };

            System.Console.WriteLine(db.Students.ToList().Count());
            db.Students.Add(student);
            db.SaveChanges();
        }
Пример #32
0
        static void Main()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<StudentSystemDbContext, Configuration>());

            using (var db = new StudentSystemDbContext())
            {
                var student = new Student
                {
                    FirstName = "Sam",
                    LastName = "Jones",
                    Number = 5203
                };

                var course = new Course
                {
                    Name = "Math",
                    Description = "Stereometrics",
                    Materials = "http://math.com"
                };

                var homework = new Homework
                {
                    Content = "Done",
                    TimeSent = new DateTime(2015, 8, 15)
                };

                db.Homeworks.Add(homework);
                student.Courses.Add(course);
                db.Students.Add(student);
                db.Courses.Add(course);
                db.SaveChanges();

                Console.WriteLine(db.Students.Count());
                Console.WriteLine(db.Courses.Count());
            }
        }
Пример #33
0
        public static void Main(string[] args)
        {
            Database.SetInitializer(new StudentSystemDbInitializer());

            using (var context = new StudentSystemDbContext())
            {
                Console.WriteLine("Task 3.1: List all students and their homework submissions:");
                var students = context.Students.Include("Homeworks");
                foreach (var student in students)
                {
                    Console.WriteLine("Student: {0} ; Submitted homeworks count: {1}", student.Name, student.Homeworks.Count());
                }

                Console.WriteLine("\nTask 3.2: List all courses and their resources:");
                var courses = context.Courses.Include("Resources");
                foreach (var course in courses)
                {
                    Console.WriteLine("Course: \"{0}\" with following resources:", course.Name);
                    foreach (var resource in course.Resources)
                    {
                        Console.WriteLine("\t- \"{0}\" - [Type: {1}]", resource.Name, resource.Type);
                    }
                }

                Console.WriteLine("\nTask 3.3: Adds a new course with some resources:");
                var newCourse = new Course
                {
                    Name = "C# Programming - Beginning",
                    Description = "Learn to code in C#",
                    StartDate = DateTime.Now,
                    Price = 0.01m,
                    Resources = new List<Resource>
                    {
                        new Resource { Name = "C# Programming", Type = ResourceType.Document, Link = "search in bookstores" },
                        new Resource { Name = "Head First C#", Type = ResourceType.Document, Link = "http://it-ebooks.info/book/251/" },
                    }
                };

                context.Courses.Add(newCourse);
                context.SaveChanges();
                Console.WriteLine("Added course ID in DB is: {0}", newCourse.CourseId);
                Console.WriteLine("This new course have {0} resources", newCourse.Resources.Count());

                Console.WriteLine("\nTask 3.4: Add a new student:");
                var newStudent = new Student
                {
                    Name = "Svetlin Nakov",
                    Birthday = new DateTime(1900, 1, 1),
                    RegistrationDate = DateTime.Now
                };

                context.Students.Add(newStudent);
                context.SaveChanges();
                Console.WriteLine("Added student ID in DB is: {0}", newStudent.StudentId);

                Console.WriteLine("\nTask 3.5: Add a new resource:");
                var newResource = new Resource
                {
                    Name = "Book with pictures",
                    Type = ResourceType.Document,
                    Link = "look into kindergarden",
                    Course = context.Courses.FirstOrDefault(),
                };

                context.Resources.Add(newResource);
                context.SaveChanges();
                Console.WriteLine("Added resource ID in DB is {0} and is assigned to course \"{1}\"", newResource.ResourceId, newResource.Course.Name);
            }
        }
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemDbContext, Configuration>());
            var db = new StudentSystemDbContext();

            //Add new student
            db.Students.AddOrUpdate(new Student
            {
                Name = "Nakov",
                Birthday = new DateTime(1980, 1, 1),
                RegistrationDate = new DateTime(2015, 2, 1)
            });

            // Add new resource
            var resource1 = new Resource
            {
                Name = "Nakov video",
                TypeOfResourse = TypeOfResourse.Video,
                Link = "www.youtube.com"
            };

            var resource2 = new Resource
            {
                Name = "Link",
                Link = "www.dir.bg",
                TypeOfResourse = TypeOfResourse.Other,
            };

            db.Resources.AddOrUpdate(resource1, resource2);

            // Add new courses
            var course1 = new Course
            {
                Name = "C# Intro",
                Discription = "jgds gldsldjf dgj dgf g ",
                StartDate = new DateTime(2014, 1, 1),
                EndDate = new DateTime(2014, 1, 30),
                Price = 180
            };

            var course2 = new Course
            {
                Name = "Seminar 1",
                Discription = "jgds gldsldjf dgj dgf g ",
                StartDate = new DateTime(2015, 2, 1),
                EndDate = new DateTime(2015, 2, 25),
                Price = 0
            };

            course1.Resources.Add(resource1);
            course2.Resources.Add(resource2);
            db.Courses.AddOrUpdate(course1, course2);

            db.SaveChanges();

            // Lists all students and their homework submissions
            Console.WriteLine(" * Lists all students and their homework submissions");

            var students = db.Students
                .Include(s => s.Homeworks)
                .Select(s => new
                {
                    s.Name,
                    s.Homeworks
                });

            foreach (var student in students)
            {
                Console.WriteLine(student.Name);
                var homeworks = student.Homeworks;
                if (homeworks.Count == 0)
                {
                    Console.WriteLine("    no homeworks");
                }
                else
                {
                    foreach (var homework in homeworks)
                    {
                        Console.WriteLine("    - " + homework.DateAndTime);
                    }
                }
            }

            Console.WriteLine();

            // List all course and their resources
            Console.WriteLine(" * List all course and their resources");

            var courses = db.Courses
                .Include(c => c.Resources)
                .Select(c => new
                {
                    c.Name,
                    c.Resources
                });

            foreach (var course in courses)
            {
                Console.WriteLine(course.Name);
                var resourses = course.Resources;
                if (resourses.Count == 0)
                {
                    Console.WriteLine("    no resourses");
                }
                else
                {
                    foreach (var resourse in resourses)
                    {
                        Console.WriteLine("    {0}; {1}",resourse.Name, resourse.Link);
                    }
                }
            }
        }