Example #1
0
        private void btnFilterDelete_Click(object sender, RoutedEventArgs e)
        {
            //using (EfContext context = new EfContext())
            //{
            //    using (TransactionScope scope = new TransactionScope())
            //    {
            //        TreeViewItem item = treeView1.SelectedItem as TreeViewItem;
            //        if (item != null)
            //        {
            //            ItemsControl parent = GetSelectedTreeViewItemParent(item);
            //            TreeViewItem treeItem = parent as TreeViewItem;

            //            if (treeItem != null )
            //            {

            //                MyTreeViewItem myValue = item.Header as MyTreeViewItem;
            //                MyTreeViewItem parentItem = treeItem.Header as MyTreeViewItem;
            //                var delValue = context.FilterValues.SingleOrDefault(f => f.Id.ToString() == myValue.Id);
            //                var delGroup = context.VFilterNameGroups
            //                    .SingleOrDefault(f => f.FilterNameId.ToString() == parentItem.Id
            //                                            && f.FilterValueId.ToString() == myValue.Id);
            //                if (delValue != null)
            //                {
            //                    context.VFilterNameGroups.Remove(delGroup);
            //                    context.FilterValues.Remove(delValue);
            //                    context.SaveChanges();
            //                }
            //                refreshTreeView();
            //            }
            //            else
            //            {
            //                MyTreeViewItem myName = treeView1.SelectedItem as MyTreeViewItem;
            //                var delName = context.FilterNames.SingleOrDefault(f => f.Name == myName.Name);
            //                context.FilterNames.Remove(delName);
            //            }
            //        }
            //        scope.Complete();
            //    }
            //}
            //refreshTreeView();

            TreeViewItem item = treeView1.SelectedItem as TreeViewItem;

            if (item != null)
            {
                ItemsControl parent   = GetSelectedTreeViewItemParent(item);
                TreeViewItem treeitem = parent as TreeViewItem;
                if (treeitem != null)
                {
                    MyTreeViewItem myValue    = item.Header as MyTreeViewItem;
                    MyTreeViewItem parentItem = treeitem.Header as MyTreeViewItem;

                    _filterProvider.RemoveFilterValue(int.Parse(myValue.Id), int.Parse(parentItem.Id));
                }
                else
                {
                    _filterProvider.RemoveFilterName(item);
                }
                refreshTreeView();
            }
        }