public static CourseStudent GetCourseStudent(int id) { CoursesEntities db = new CoursesEntities(); CourseStudent res = db.CourseStudents.ToList().Find(p => p.Id == id); if (res != null) { res.Cours.ToString(); res.Student.ToString(); } db.Dispose(); return(res); }
public static bool DelBindStudentToCourse(int id) { CoursesEntities db = new CoursesEntities(); CourseStudent courseStudent = db.CourseStudents.Find(id); if (courseStudent != null) { db.CourseStudents.Remove(courseStudent); try { db.SaveChanges(); db.Dispose(); return(true); } catch (Exception) { db.Dispose(); return(false); } } return(false); }
//edit manytomany db public static CourseStudent EditBindStudentToCourse(int id, bool isPaid, int?sertificateNumber) { CoursesEntities db = new CoursesEntities(); CourseStudent courseStudent = db.CourseStudents.Find(id); if (courseStudent != null) { courseStudent.IsPaid = isPaid; courseStudent.SertificateNumber = sertificateNumber; try { db.SaveChanges(); db.Dispose(); return(courseStudent); } catch (System.Data.Entity.Validation.DbEntityValidationException) { db.Dispose(); return(null); } } return(null); }
public static CourseStudent BindStudentToCourse(int studentId, int courseId) { CoursesEntities db = new CoursesEntities(); //if (db.CourseStudents.Where(p => p.StudentId == studentId && p.CourseId == courseId).Count() != 0) // return null; CourseStudent newCourseStudent = new CourseStudent(); newCourseStudent.CourseId = courseId; newCourseStudent.StudentId = studentId; newCourseStudent.IsPaid = false; db.CourseStudents.Add(newCourseStudent); try { db.SaveChanges(); db.Dispose(); } catch (System.Data.Entity.Validation.DbEntityValidationException) { db.Dispose(); return(null); } return(newCourseStudent); }