private static void SeedCourses(StudentSystemDbContext db) { var courseNames = new string[] { "C#", "Ruby on Rails", "JavaScript", "Angular", "React", "OOP Advanced", "C# Web Development" }; for (int i = 0; i < courseNames.Length; i++) { var year = random.Next(1800, 2019); var month = random.Next(1, 13); var date = random.Next(1, 29); var endDate = new DateTime(year, month, date); var course = new Course { Name = courseNames[i], StartDate = DateTime.Now, EndDate = endDate, Price = random.Next(20, 472), }; db.Add(course); } db.SaveChanges(); }
private static void SeedResources(StudentSystemDbContext db) { var resourseNames = new string[] { "LINQ", "Primal Data types", "Reference Data types", "OOP", "Files", "Defining classes", "SQL Queries" }; for (int i = 0; i < resourseNames.Length; i++) { var resource = new Resource { Name = resourseNames[i], CourseId = random.Next(1, 8) }; db.Add(resource); } db.SaveChanges(); }
private static void SeedHomeworks(StudentSystemDbContext db) { var homeworkNames = new string[] { "homework1", "homework2", "homework3", "homework4", "homework5", "homework6", "homework7", "homework8", "homework9", "homework10", "homework11", }; for (int i = 0; i < homeworkNames.Length; i++) { var homework = new HomeworkSubmission { StudentId = random.Next(1, 10), Content = "Some Random Content", ContentType = (ContentType)((random.Next(1, 4))), CourseId = random.Next(1, 8) }; db.Add(homework); } db.SaveChanges(); }
private static void SeedStudents(StudentSystemDbContext db) { var names = new string[] { "Pesho", "Gosho", "Test", "Stamat", "Georgi", "Ivan", "Misho", "Nasko", "Emko" }; for (int i = 0; i < names.Length; i++) { var year = random.Next(1800, 2019); var month = random.Next(1, 13); var date = random.Next(1, 29); var birthDate = new DateTime(year, month, date); var student = new Student { Name = names[i], BirthDate = birthDate, }; db.Add(student); } db.SaveChanges(); }
private static void SeedData(StudentSystemDbContext db) { const int totalStudents = 25; const int totalCourses = 12; var currentDate = DateTime.Now; // Add Students for (int i = 0; i < totalStudents; i++) { db.Add(new Student { Name = $"Student {i}", RegistrationDate = currentDate.AddDays(i), Birthday = currentDate.AddYears(-20).AddDays(i), PhoneNumber = $"Phone number : +359{i}" }); } db.SaveChanges(); // Add Courses var addedCourses = new List <Course>(); for (int i = 0; i < totalCourses; i++) { var course = new Course { Name = $"Curse {i}", Desctiption = $"Curse Details {i}", StartDate = currentDate.AddDays(i), EndDate = currentDate.AddDays(i + 20), Price = 100 * i }; addedCourses.Add(course); db.Courses.Add(course); } db.SaveChanges(); // Student in Course var studentsIds = db .Students .Select(x => x.Id) .ToList(); for (int i = 0; i < totalCourses; i++) { var studentInCourse = random.Next(2, totalStudents / 2); var currentCourse = addedCourses[i]; for (int j = 0; j < studentInCourse; j++) { var studentsId = studentsIds[random.Next(0, studentsIds.Count)]; if (!currentCourse.Students.Any(x => x.StudentId == studentsId)) { currentCourse.Students.Add(new StudentCourse { StudentId = studentsId }); } else { j--; } } var resourcesInCourse = random.Next(2, 20); var type = new[] { 0, 1, 2, 999 }.ToArray(); for (int j = 0; j < resourcesInCourse; j++) { currentCourse.Resources.Add(new Resource { Name = $"Resource {i} {j}", Url = $"URL {i} {j}", TypeOfRecurces = (ResourceType)type[random.Next(0, type.Length)] }); } } db.SaveChanges(); // Homeworks for (int i = 0; i < totalCourses; i++) { var currentCourse = addedCourses[i]; var studentInCourseIds = currentCourse .Students .Select(x => x.StudentId) .ToList(); for (int j = 0; j < studentInCourseIds.Count; j++) { var totalHomework = random.Next(2, 5); for (int k = 0; k < totalHomework; k++) { db.Homeworks.Add(new Homework { Content = $"Content Homework {i}", ContentType = ContentType.Zip, SubmissionDate = currentDate.AddDays(-i), StudentId = studentInCourseIds[j], CourseId = currentCourse.Id }); } } db.SaveChanges(); } }
private static void SeedDate(StudentSystemDbContext db) { var currentDate = DateTime.Now; var totalStudents = 20; var totalCourses = 10; //Add students in database for (int i = 1; i < totalStudents; i++) { db.Add(new Student { Name = $"Student {i}", RegistrationDate = currentDate.AddDays(i), Birthday = currentDate.AddYears(-20).AddDays(i), Phone = $"Phone.... 0894{i}" }); } db.SaveChanges(); //Add courses in database var addedCourses = new List <Course>(); for (int i = 0; i < totalCourses; i++) { var course = new Course { Name = $"Course {i}", Description = $"Course Details {i}", Price = 100 * i, StartDate = currentDate.AddDays(i), EndDate = currentDate.AddDays(10 + i) }; addedCourses.Add(course); db.Courses.Add(course); } db.SaveChanges(); var random = new Random(); var studentsIds = db .Students .Select(s => s.Id) .ToList(); //Studens in Courses for (int i = 0; i < totalCourses; i++) { var currentCurse = addedCourses[i]; var studentInCoourse = random.Next(2, totalStudents / 2); for (int j = 0; j < studentInCoourse; j++) { var studentId = studentsIds[random.Next(0, studentsIds.Count)]; if (!currentCurse.Students.Any(s => s.StudentId == studentId)) { currentCurse.Students.Add(new StudentCourse { StudentId = studentId }); } else { j--; } } var resourcesInCourse = random.Next(2, 8); var types = new[] { 0, 1, 2, 999 }; currentCurse.Resources.Add(new Resource { Name = $"Resourses {i}", URL = $"Url {i}", Type = (ResourceType)(types[random.Next(0, types.Length)]) }); } db.SaveChanges(); //Add homeworks in database for (int i = 0; i < totalCourses; i++) { var currentCourse = addedCourses[i]; var studentInCourseIds = currentCourse .Students .Select(s => s.StudentId) .ToList(); for (int j = 0; j < studentInCourseIds.Count; j++) { var totalHomeworks = random.Next(2, 5); for (int k = 0; k < totalHomeworks; k++) { db.Homeworks.Add(new Homework { Content = $"Content Homework {i}", SubmissionDate = currentDate.AddDays(-i), Type = ContentType.Zip, StudentId = studentInCourseIds[j], CourseId = currentCourse.Id }); } } db.SaveChanges(); } }