Exemplo n.º 1
0
        /// <summary>
        /// refresh articles for selected KnowledgeBaseGroup
        /// </summary>
        private void RefreshSelectedKnowledgeGroupArticles()
        {
            var adaptor = new CommunicationAdaptor();

            Task.Factory.StartNew(() =>
            {
                KnowledgeArticleCommunicationControl.IsInitialized = false;
                List <CommunicationItemViewModel> result           = null;
                var selectedKnowledgeGroup = SelectedKnowledgeGroup as KnowledgeGroupViewModel;
                var articles = GetKnowledgeBaseArticles(selectedKnowledgeGroup);
                if (articles != null && articles.Count() > 0)
                {
                    result = new List <CommunicationItemViewModel>();
                    foreach (var i in articles)
                    {
                        result.Add(adaptor.KnowledgeBaseArticle2KnowledgeBaseArticleCommunicationViewModel(i));
                    }
                    //result = articles.Select(n => (adaptor.KnowledgeBaseArticle2KnowledgeBaseArticleCommunicationViewModel(n) as CommunicationItemViewModel)).OfType<CommunicationItemViewModel>().ToList();
                }
                return(result);
            }).ContinueWith(t =>
            {
                OnUIThread(() =>
                {
                    if (t.Exception == null)
                    {
                        KnowledgeArticleCommunicationControl.ClearAllCommunicationItems();
                        KnowledgeArticleCommunicationControl.AppendCommunucationItems(t.Result);
                    }
                    KnowledgeArticleCommunicationControl.IsInitialized = true;
                });
            });
        }
Exemplo n.º 2
0
        private void CommitSelectedKnowledgeGroupArticles()
        {
            var adaptor              = new CommunicationAdaptor();
            var selectedGroupId      = (_selectedKnowledgeGroup as KnowledgeGroupViewModel) != null ? (_selectedKnowledgeGroup as KnowledgeGroupViewModel).OriginalItem.KnowledgeBaseGroupId : null;
            var communicationControl = KnowledgeArticleCommunicationControl as KnowledgeArticleCommunicationControlViewModel;
            var itemsForDelete       = communicationControl.GetItemsByState(CommunicationItemState.Deleted);
            var itemsForAppend       = communicationControl.GetItemsByState(CommunicationItemState.Appended);
            var itemsForModify       = communicationControl.GetItemsByState(CommunicationItemState.Modified);

            Task.Factory.StartNew(() =>
            {
                var repository       = _repositoryFactory.GetRepositoryInstance();
                ShowLoadingAnimation = true;
                // delete
                if (itemsForDelete != null && itemsForDelete.Count() > 0)
                {
                    foreach (CommunicationItemViewModel item in itemsForDelete)
                    {
                        KnowledgeBaseArticle original = adaptor.KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(item as CommunicationItemKnowledgeBaseArticleViewModel);
                        //SyncAttach(original, null);
                        repository.Attach(original);
                        repository.Remove(original);
                    }
                }
                // append
                if (itemsForAppend != null && itemsForAppend.Count() > 0 && selectedGroupId != null)
                {
                    foreach (CommunicationItemViewModel item in itemsForAppend)
                    {
                        KnowledgeBaseArticle article = adaptor.KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(item as CommunicationItemKnowledgeBaseArticleViewModel);
                        article.GroupId = selectedGroupId;
                        //SyncAttach(null, article);
                        repository.Add(article);
                    }
                }
                // modify
                if (itemsForModify != null && itemsForModify.Count() > 0)
                {
                    foreach (CommunicationItemViewModel item in itemsForModify)
                    {
                        var article     = adaptor.KnowledgeBaseArticleCommunicationViewModel2KnowledgeBaseArticle(item as CommunicationItemKnowledgeBaseArticleViewModel);
                        article.GroupId = selectedGroupId;
                        var original    = repository.KnowledgeBaseArticles.Where(x => x.KnowledgeBaseArticleId == article.KnowledgeBaseArticleId).SingleOrDefault();
                        //SyncAttach(original, article);
                        repository.Attach(original);
                        OnUIThread(() => original.InjectFrom(article));
                    }
                }
                int i = repository.UnitOfWork.Commit();
            })
            .ContinueWith(t =>
            {
                ShowLoadingAnimation = false;
            });
        }