示例#1
0
        private void AddNewSubject(object sender, RoutedEventArgs e)
        {
            var addDialog = new Dialogs.AddModifySubjectDialog(_teacherRepository.GetAllTeachers().ToList());

            addDialog.ShowDialog();
            if (!addDialog.IsSelected)
            {
                return;
            }

            int insertedId = -1;

            try
            {
                insertedId = _subjectRepository.AddNewSubject(addDialog.SelectedSubjectName, addDialog.SelectedTeacher.TeacherId, addDialog.SelectedSubjectDescription);
            }
            catch (SqlException ex)
            {
                if (ex.Number == 50005)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            _displayedSubjects.Add(new Subject()
            {
                SubjectId          = insertedId,
                SubjectDescription = addDialog.SelectedSubjectDescription,
                TeacherId          = addDialog.SelectedTeacher.TeacherId,
                Name = addDialog.SelectedSubjectName
            });
            SubjectList.Items.Refresh();
            AwailableSubjects.Items.Refresh();
        }
示例#2
0
        private void ModifySubject(object sender, ExecutedRoutedEventArgs e)
        {
            var selectedSubject = SubjectList.SelectedItem as Subject;

            if (selectedSubject == null)
            {
                return;
            }
            var modifySubjectDialog = new Dialogs.AddModifySubjectDialog(selectedSubject, _teacherRepository.GetAllTeachers().ToList());

            modifySubjectDialog.ShowDialog();
            if (!modifySubjectDialog.IsSelected)
            {
                return;
            }
            _subjectRepository.ModifySubject(selectedSubject.SubjectId,
                                             modifySubjectDialog.SelectedSubjectName,
                                             modifySubjectDialog.SelectedSubjectDescription,
                                             modifySubjectDialog.SelectedTeacher.TeacherId);
            var targetSubject = _displayedSubjects.First(subj => subj.SubjectId == selectedSubject.SubjectId);

            targetSubject.Name = modifySubjectDialog.SelectedSubjectName;
            targetSubject.SubjectDescription = modifySubjectDialog.SelectedSubjectDescription;
            targetSubject.TeacherId          = modifySubjectDialog.SelectedTeacher.TeacherId;
            AwailableSubjects.Items.Refresh();
            SubjectList.Items.Refresh();
        }