コード例 #1
0
        private void addEmpl_Click(object sender, RoutedEventArgs e)
        {
            Employee          employee          = new Employee();
            NewEmployeeWindow newEmployeeWindow = new NewEmployeeWindow(employee);
            var result = newEmployeeWindow.ShowDialog();

            if (result == true)
            {
                context.Employees.Add(employee);
                context.SaveChanges();
                newEmployeeWindow.Close();
            }
        }
コード例 #2
0
        private void editEmpl_Click(object sender, RoutedEventArgs e)
        {
            Employee          employee          = dGrid.SelectedItem as Employee;
            NewEmployeeWindow newEmployeeWindow = new NewEmployeeWindow(employee);
            var result = newEmployeeWindow.ShowDialog();

            if (result == true)
            {
                context.SaveChanges();
                newEmployeeWindow.Close();
            }
            else
            {
                // вернуть начальное значение
                context.Entry(employee).Reload();
                // перегрузить DataContext
                dGrid.DataContext = null;
                dGrid.DataContext = context.Employees.Local;
            }
        }