public void DeleteRecord(int id) { var data = context.Teachers.SingleOrDefault(s => s.TeacherId == id); context.Teachers.Remove(data); context.SaveChanges(); }
public static void Import(SchoolDatabaseContext db, int count) { var generator = RandomGenerator.Instance; var studentsIDs = db.Students.Select(s => s.Id).OrderBy(s => Guid.NewGuid()).ToList(); for (int i = 0; i < count; i++) { var course = new Course() { Name = generator.GetRandomString(5, 20), Description = generator.GetRandomString(50, 200), Materials = generator.GetRandomString(10, 100), }; var studentsInCourse = generator.GetRandomNumber(20, 30); for (int j = 0; j < studentsInCourse; j++) { var studentID = studentsIDs[generator.GetRandomNumber(0, studentsIDs.Count - 1)]; course.Students.Add(db.Students.Where(s => s.Id == studentID).First()); } db.Courses.Add(course); } db.SaveChanges(); Console.WriteLine("{0} Courses imported", count); }
public static void Import(SchoolDatabaseContext db, int count) { var generator = RandomGenerator.Instance; var studentsIDs = db.Students.Select(s => s.Id).OrderBy(s => Guid.NewGuid()).ToList(); for (int i = 0; i < count; i++) { var course = new Course() { Name = generator.GetRandomString(5, 20), Description = generator.GetRandomString(50, 200), Materials = generator.GetRandomString(10, 100), }; var studentsInCourse = generator.GetRandomNumber(20, 30); for (int j = 0; j < studentsInCourse; j++) { var studentID = studentsIDs[generator.GetRandomNumber(0, studentsIDs.Count - 1)]; course.Students.Add(db.Students.Where(s => s.Id == studentID).First()); } db.Courses.Add(course); } db.SaveChanges(); Console.WriteLine("{0} Courses imported", count); }
public static void Import(SchoolDatabaseContext db, int count) { var generator = RandomGenerator.Instance; var coursesIDs = db.Courses.Select(c => c.Id).OrderBy(c => Guid.NewGuid()).ToList(); for (int i = 0; i < count; i++) { var courseID = coursesIDs[generator.GetRandomNumber(0, coursesIDs.Count - 1)]; var course = db.Courses .Where(c => c.Id == courseID) .First(); var studentsIDsFromCourse = course.Students.Select(s => s.Id).ToList(); var studentID = studentsIDsFromCourse[generator.GetRandomNumber(0, studentsIDsFromCourse.Count - 1)]; db.Homeworks.Add(new Homework() { Content = generator.GetRandomString(100, 300), TimeSent = generator.GetRandomDate(DateTime.Now.AddDays(-100), DateTime.Now), StudentId = studentID, CourseId = courseID }); } db.SaveChanges(); Console.WriteLine("{0} Homeworks imported", count); }
public static void Import(SchoolDatabaseContext db, int count) { var generator = RandomGenerator.Instance; var coursesIDs = db.Courses.Select(c => c.Id).OrderBy(c => Guid.NewGuid()).ToList(); for (int i = 0; i < count; i++) { var courseID = coursesIDs[generator.GetRandomNumber(0, coursesIDs.Count - 1)]; var course = db.Courses .Where(c => c.Id == courseID) .First(); var studentsIDsFromCourse = course.Students.Select(s => s.Id).ToList(); var studentID = studentsIDsFromCourse[generator.GetRandomNumber(0, studentsIDsFromCourse.Count - 1)]; db.Homeworks.Add(new Homework() { Content = generator.GetRandomString(100, 300), TimeSent = generator.GetRandomDate(DateTime.Now.AddDays(-100), DateTime.Now), StudentId = studentID, CourseId = courseID }); } db.SaveChanges(); Console.WriteLine("{0} Homeworks imported", count); }
public String Add(Course course) { if (ModelState.IsValid) { Dbc.Course.Add(course); Dbc.SaveChanges(); } return("Course added to database: " + course.CourseId + ", " + course.Name); }
public ActionResult Add(Student studentView) { if (ModelState.IsValid) { //Student student = new Student() { CourseId=studentView.CourseId, FirstName = studentView.FirstName, LastName = studentView.LastName}; Dbc.Student.Add(studentView); Dbc.SaveChanges(); } return(RedirectToAction("ShowList")); }
public ActionResult Add(School school) { if (ModelState.IsValid) { Dbc.School.Add(school); Dbc.SaveChanges(); } return(RedirectToAction("ShowList")); }
public static void Import(SchoolDatabaseContext db, int count) { var generator = RandomGenerator.Instance; for (int i = 0; i < count; i++) { db.Students.Add(new Student() { Name = generator.GetRandomString(5, 20), Number = generator.GetRandomNumber(10000, 99999), }); } db.SaveChanges(); Console.WriteLine("{0} Students imported", count); }