private void btnRegisterClient_Click(object sender, RoutedEventArgs e) { if (cbStudent.SelectedItem != null && cbLecture.SelectedItem != null) { ClientLecture cl = new ClientLecture(); cl.Client = (Client)cbStudent.SelectedItem; cl.Lecture = (Lecture)cbLecture.SelectedItem; IQueryable <ClientLecture> duplicateCL = from dcl in dataContext.ClientLectures where dcl.Client == cl.Client where dcl.Lecture == cl.Lecture select dcl; if (duplicateCL.Count() == 0) { dataContext.ClientLectures.InsertOnSubmit(cl); dataContext.SubmitChanges(); RefreshTable(); } else { MessageBox.Show("Student is already registered in that lecture."); } } else { MessageBox.Show("Please select a student and a lecture to register."); } }
private void btnUnregisterClient_Click(object sender, RoutedEventArgs e) { if (cbStudent.SelectedItem != null && cbLecture.SelectedItem != null) { try { ClientLecture cl = (from cL in dataContext.ClientLectures where cL.ClientId == (int)cbStudent.SelectedValue where cL.LectureId == (int)cbLecture.SelectedValue select cL).First(); dataContext.ClientLectures.DeleteOnSubmit(cl); dataContext.SubmitChanges(); RefreshTable(); } catch { MessageBox.Show("Student not found in that lecture."); } } else { MessageBox.Show("Please select a student and a lecture to unregister."); } }