private static void CreateSampleData(StudentSystemContext db) { var student = new Student() { StudentId = 1, Name = "Georgi Ivanov", Number = 2000, DateOfBirth = new DateTime(1994, 01, 16) }; var course = new Course() { Name = "HQC", Description = string.Empty, Materials = "SOLID, Design Patterns" }; var homework = new Homework() { HomeworkId = 1, CourseId = "HQC", StudentId = 1, Course = course, Student = student, DateSent = new DateTime(2015, 10, 10) }; student.Courses.Add(course); student.Homeworks.Add(homework); course.Students.Add(student); course.Homeworks.Add(homework); db.Courses.Add(course); db.Homeworks.Add(homework); db.Students.Add(student); db.SaveChanges(); }
public void SeedHomeworks(int homeworksCount) { for (int i = 0; i < homeworksCount; i++) { int year = randomGenerator.GetRandomInteger(1997, 2015); int month = randomGenerator.GetRandomInteger(1, 12); int day = randomGenerator.GetRandomInteger(1, 28); var hw = new Homework() { Content = randomGenerator.GetRandomString(), TimeSent = new DateTime(year, month, day) }; db.Homeworks.Add(hw); if (db.ChangeTracker.Entries <Homework>().Count() > 1000) { ResetDb(); } } ResetDb(); }
private static void SeedData(StudentContext context) { DateTime currentDateTime = DateTime.Now; Random rnd = new Random(); // Courses Console.WriteLine($"Seeding Courses..."); for (int i = 0; i < 30; i++) { Course course = new Course() { Description = $"Description {i}", EndDate = currentDateTime.AddDays(20), Name = $"Course {i}", Price = i * 10, StartDate = currentDateTime.AddDays(-30) }; context.Courses.Add(course); } context.SaveChanges(); // Resource Console.WriteLine($"Seeding Resource..."); List <Course> courses = context .Courses .ToList(); for (int i = 0; i < 90; i++) { Resource resource = new Resource() { Name = $"Resource {i}", TypeOfResource = (TypeOfResource)rnd.Next(0, 4), Url = $"www.{i}.com", Course = courses[rnd.Next(0, courses.Count)] }; context.Resourceses.Add(resource); } context.SaveChanges(); // Students for (int i = 0; i < 30; i++) { Student student = new Student() { Name = $"Student{i}", BirthDate = currentDateTime.AddYears(-27), Phonenumber = $"08820000{i}", RegistrationTime = currentDateTime.AddDays(-30 - i) }; context.Students.Add(student); } context.SaveChanges(); // Homeworks Console.WriteLine($"Seeding Homeworks..."); List <Student> students = context.Students.ToList(); for (int i = 0; i < 90; i++) { Homework homework = new Homework() { Content = $"Content {i}", ContentType = (ContentType)rnd.Next(0, 3), SubmissionDate = currentDateTime.AddMinutes(-20 - i), Course = courses[rnd.Next(0, courses.Count)], Student = students[rnd.Next(0, students.Count)] }; context.Homeworks.Add(homework); } context.SaveChanges(); // StudentCourses Console.WriteLine($"Seeding StudentResources..."); for (int i = 0; i < courses.Count; i++) { courses[i].Students.Add(new StudentCourses() { Student = students[rnd.Next(0, students.Count)] }); } context.SaveChanges(); }