예제 #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();
        }