private static void AddCourse(string courseName) { using (var context = new StudentCourse()) { var course = new Course() { CoursedName = courseName }; context.Courses.Add(course); context.SaveChanges(); } }
private static bool Delete(int studentID) { using (var context = new StudentCourse()) { var student = context.Students.FirstOrDefault(x => x.StudentID == studentID); if (student == null) { return(false); } context.Students.Remove(student); context.SaveChanges(); return(true); } }
private static void Insert(string studentName, int studentAge, string studentGender, int studentCourseID) { using (var context = new StudentCourse()) { var student = new Student() { StudentName = studentName, StudentAge = studentAge, StudentGender = studentGender, CourseID = studentCourseID }; context.Students.Add(student); context.SaveChanges(); } }
private static void Update(string studentName, int studentAge, string studentGender, int studentCourseID, int studentID) { using (var context = new StudentCourse()) { var student = context.Students.FirstOrDefault(x => x.StudentID == studentID); if (student != null) { student.StudentName = studentName; student.StudentAge = studentAge; student.StudentGender = studentGender; student.CourseID = studentCourseID; } context.SaveChanges(); } }