Beispiel #1
0
        private void RaiseTreeItemDelete(object knowlegeGroupViewModel)
        {
            if ((knowlegeGroupViewModel as KnowledgeGroupViewModel) != null)
            {
                SelectedKnowledgeGroup = (knowlegeGroupViewModel as KnowledgeGroupViewModel);
            }
            bool canDelete = false;

            if (SelectedKnowledgeGroup != null)
            {
                var articles = GetKnowledgeBaseArticles(SelectedKnowledgeGroup as KnowledgeGroupViewModel);
                var children = (SelectedKnowledgeGroup as KnowledgeGroupViewModel).GetChildren((SelectedKnowledgeGroup as KnowledgeGroupViewModel).OriginalItem);
                //var subGroup = _customersRepository.KnowledgeBaseGroups.Where(x => x.Parent.KnowledgeBaseGroupId == (SelectedKnowledgeGroup as KnowledgeGroupViewModel).OriginalItem.KnowledgeBaseGroupId).ToList();
                canDelete = (articles != null && articles.Count() == 0 && children != null && children.Count() == 0);
            }

            if (CommonConfirmRequest != null && canDelete)
            {
                CommonConfirmRequest.Raise(
                    new Confirmation
                {
                    Title   = "Remove group?".Localize(),
                    Content = (SelectedKnowledgeGroup as KnowledgeGroupViewModel).InnerItem.Name
                },
                    (x) =>
                {
                    if (x.Confirmed)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            ShowLoadingAnimation = true;
                            (SelectedKnowledgeGroup as KnowledgeGroupViewModel).RemoveFromDB();
                        })
                        .ContinueWith(t =>
                        {
                            if (t.Exception == null)
                            {
                                OnUIThread(() =>
                                {
                                    if ((SelectedKnowledgeGroup as KnowledgeGroupViewModel).Parent != null)
                                    {
                                        SelectedKnowledgeGroup = (SelectedKnowledgeGroup as KnowledgeGroupViewModel).Parent;
                                        (SelectedKnowledgeGroup as KnowledgeGroupViewModel).Refresh();
                                    }
                                    else
                                    {
                                        RootKnowledgeGroups.Remove(SelectedKnowledgeGroup as KnowledgeGroupViewModel);
                                        SelectedKnowledgeGroup = null;
                                    }
                                    //TODO: update treeview
                                });
                            }
                            ShowLoadingAnimation = false;
                        });
                    }
                }
                    );
            }
        }
Beispiel #2
0
        public void Drop(DropInfo dropInfo)
        {
            var droppedVM = dropInfo.Data;
            var targetVM  = dropInfo.TargetItem;

            if (droppedVM is IHierarchy)
            {
                // preparing to refresh UI
                var sourceVM       = droppedVM as HierarchyViewModelBase;
                var sourceParentVM = sourceVM.Parent;

                Task.Factory.StartNew(() =>
                {
                    ShowLoadingAnimation = true;
                    ((IHierarchy)droppedVM).SetParent(null, targetVM);
                })
                .ContinueWith(t =>
                {
                    if (t.Exception == null)
                    {
                        OnUIThread(() =>
                        {
                            // refresh UI
                            if (sourceParentVM != null)
                            {
                                sourceParentVM.LoadChildrens();
                            }
                            else
                            {
                                RootKnowledgeGroups.Remove(droppedVM as KnowledgeGroupViewModel);
                            }
                            ((HierarchyViewModelBase)targetVM).LoadChildrens();
                        });
                    }
                    ShowLoadingAnimation = false;
                });
            }
        }