Example #1
0
        private void NewButton_Click(object sender, RoutedEventArgs e)
        {
            var detailWindow = new EmployeeDetailWindow();

            if (detailWindow.ShowDialog() != true)
            {
                return;
            }

            _ctx.Employees.Add(detailWindow.Model);
            _ctx.SaveChanges();

            LoadEmployees();
        }
Example #2
0
        private void UpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (MainGrid.SelectedItem == null)
            {
                return;
            }

            var detailWindow = new EmployeeDetailWindow(MainGrid.SelectedItem as Employee);

            if (detailWindow.ShowDialog() != true)
            {
                return;
            }

            // Siccome il model รจ stato creato dal DbContext,
            // il DbContext conosce lo stato dell'oggetto,
            // quindi non serve fare Attach/Update, modificare lo State, ecc.

            // Basta solo salvare:
            _ctx.SaveChanges();

            LoadEmployees();
        }