示例#1
0
        private void FacultyUpdate_Click(object sender, RoutedEventArgs e)
        {
            FacultiesEditor facultiesEditor = new FacultiesEditor();
            FacultiesEditor changeEditor    = new FacultiesEditor();

            facultiesEditor.Action.Content = "Найти";
            if (facultiesEditor.ShowDialog() == true)
            {
                int index     = 0;
                var faculties = db.Faculties.ToList();
                foreach (var faculty in faculties)
                {
                    index++;
                    if (faculty.Name == facultiesEditor.Name.Text)
                    {
                        MessageBox.Show("Факультет найден!");
                        changeEditor.Action.Content = "Сохранить изменения";
                        if (changeEditor.ShowDialog() == true)
                        {
                            faculty.Name = changeEditor.Name.Text;
                            db.SaveChanges();
                            LoadFaculties();
                            MessageBox.Show("Факультет успешно изменен!", "Сообщение",
                                            MessageBoxButton.OK, MessageBoxImage.Information);
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        private void FacultyDelete_Click(object sender, RoutedEventArgs e)
        {
            FacultiesEditor facultiesEditor = new FacultiesEditor();

            facultiesEditor.Action.Content = "Удалить";
            if (facultiesEditor.ShowDialog() == true)
            {
                var  faculties = db.Faculties.ToList();
                bool success   = false;
                foreach (var faculty in faculties)
                {
                    if (faculty.Name == facultiesEditor.Name.Text)
                    {
                        db.Faculties.Remove(faculty);
                        db.SaveChanges();
                        LoadFaculties();
                        success = true;
                        MessageBox.Show("Факультет успешно удален!", "Сообщение",
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    }
                }
                if (!success)
                {
                    MessageBox.Show("Факультет не найден!", "Сообщение",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
示例#3
0
        private void FacultyCreate_Click(object sender, RoutedEventArgs e)
        {
            FacultiesEditor facultiesEditor = new FacultiesEditor();

            facultiesEditor.Action.Content = "Добавить";
            if (facultiesEditor.ShowDialog() == true)
            {
                db.Faculties.Add(new Faculties()
                {
                    Name = facultiesEditor.Name.Text
                });
                db.SaveChanges();
                LoadFaculties();
                MessageBox.Show("Факультет успешно добавлен!", "Сообщение",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }