Beispiel #1
0
        public void Add()
        {
            DataGrid dataGrid = GetDataGrid();

            managedType newObject = CreateManagedInstance();
            bool?       result    = new AddEditPopUp(newObject, Constructor, Validate).ShowDialog();

            if (!(bool)result)
            {
                return;
            }

            var newList = dataGrid.ItemsSource.Cast <managedType>().ToList();

            newList.Insert(0, newObject);
            dataGrid.ItemsSource = newList;

            db.Set <managedType>().Add(newObject);
        }
Beispiel #2
0
        public void Edit()
        {
            DataGrid dataGrid = GetDataGrid();
            var      list     = dataGrid.SelectedItems;

            if (list.Count == 0)
            {
                MessageBox.Show("Выделите строчку для изменения");
                return;
            }

            bool?result = new AddEditPopUp(list[0], Constructor, Validate).ShowDialog();


            if (!(bool)result)
            {
                db.ChangeTracker.Entries().ToList().ForEach(ent => ent.Reload());
                dataGrid.ItemsSource = db.Set <managedType>().ToList();
                return;
            }

            db.SaveChanges();
        }