public void TermController_AddTermToContent_Throws_On_Null_ContentItem()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);

            //Act, Arrange
            Assert.Throws <ArgumentNullException>(() => termController.AddTermToContent(term, null));
        }
        public void TermController_AddTermToContent_Throws_On_Null_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            ContentItem content = ContentTestHelper.CreateValidContentItem();

            //Act, Arrange
            Assert.Throws <ArgumentNullException>(() => termController.AddTermToContent(null, content));
        }
Esempio n. 3
0
        public void TermController_AddTermToContent_Should_Call_DataService_If_Valid_Params()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            ContentItem content = ContentTestHelper.CreateValidContentItem();
            Term        term    = ContentTestHelper.CreateValidSimpleTerm(Constants.VOCABULARY_ValidVocabularyId);

            // Act
            termController.AddTermToContent(term, content);

            // Assert
            mockDataService.Verify(ds => ds.AddTermToContent(term, content));
        }
Esempio n. 4
0
        private void SaveTags()
        {
            string tags = new PortalSecurity().InputFilter(_Tags, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);

            tags = HttpContext.Current.Server.HtmlEncode(tags);
            if (!string.IsNullOrEmpty(tags))
            {
                foreach (string t in tags.Split(','))
                {
                    if (!string.IsNullOrEmpty(t))
                    {
                        string tagName      = t.Trim(' ');
                        Term   existingTerm = (from term in ContentItem.Terms.AsQueryable() where term.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select term).SingleOrDefault();

                        if (existingTerm == null)
                        {
                            //Not tagged
                            TermController termController = new TermController();
                            Term           term           =
                                (from te in termController.GetTermsByVocabulary(TagVocabulary.VocabularyId) where te.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select te).
                                SingleOrDefault();
                            if (term == null)
                            {
                                //Add term
                                term      = new Term(TagVocabulary.VocabularyId);
                                term.Name = tagName;
                                termController.AddTerm(term);
                            }

                            //Add term to content
                            ContentItem.Terms.Add(term);
                            termController.AddTermToContent(term, ContentItem);
                        }
                    }
                }
            }

            IsEditMode = false;

            //Raise the Tags Updated Event
            OnTagsUpdate(EventArgs.Empty);
        }
Esempio n. 5
0
        private void SaveTags()
        {
            string tags = this._Tags;

            if (!string.IsNullOrEmpty(tags))
            {
                foreach (string t in tags.Split(','))
                {
                    if (!string.IsNullOrEmpty(t))
                    {
                        string tagName      = t.Trim(' ');
                        Term   existingTerm = (from term in this.ContentItem.Terms.AsQueryable() where term.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select term).SingleOrDefault();

                        if (existingTerm == null)
                        {
                            // Not tagged
                            TermController termController = new TermController();
                            Term           term           =
                                (from te in termController.GetTermsByVocabulary(this.TagVocabulary.VocabularyId) where te.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) select te).
                                SingleOrDefault();
                            if (term == null)
                            {
                                // Add term
                                term      = new Term(this.TagVocabulary.VocabularyId);
                                term.Name = tagName;
                                termController.AddTerm(term);
                            }

                            // Add term to content
                            this.ContentItem.Terms.Add(term);
                            termController.AddTermToContent(term, this.ContentItem);
                        }
                    }
                }
            }

            this.IsEditMode = false;

            // Raise the Tags Updated Event
            this.OnTagsUpdate(EventArgs.Empty);
        }
Esempio n. 6
0
        public void UpdateTabFromNewsEntry(TabInfo activeTab, INewsEntry newsEntry)
        {
            activeTab.TabName     = HtmlUtils.Shorten(newsEntry.Title, 200, "...");
            activeTab.Title       = activeTab.TabName;
            activeTab.Description = HtmlUtils.Shorten(
                HtmlUtils.StripTags(
                    HttpUtility.HtmlDecode(newsEntry.Description), true).Trim(), 500, "...");

            activeTab.StartDate = newsEntry.StartDate.GetValueOrDefault();
            activeTab.EndDate   = (newsEntry.EndDate != null) ? newsEntry.EndDate.Value : DateTime.MaxValue;

            var tabCtrl = new TabController();

            tabCtrl.UpdateTab(activeTab);

            var termCtrl = new TermController();

            termCtrl.RemoveTermsFromContent(activeTab);
            foreach (var term in newsEntry.ContentItem.Terms)
            {
                termCtrl.AddTermToContent(term, activeTab);
            }
        }
Esempio n. 7
0
        // TODO: Can use IEnumerable here
        static void UpdateContentItem(ContentItem contentItem, NewsEntryInfo newsEntry, List <Term> terms, List <IFileInfo> images)
        {
            // update content item after EntryId get its value
            // TODO: ContentKey should allow users to view your content item directly based on links provided from the tag search results
            // more info here: http://www.dnnsoftware.com/community-blog/cid/131963/adding-core-taxonomy-to-your-module-part-2-ndash-content-items
            contentItem.ContentKey = newsEntry.EntryId.ToString();
            NewsDataProvider.Instance.ContentController.UpdateContentItem(contentItem);

            // add images to content item
            if (images.Count > 0)
            {
                var attachmentController = new AttachmentController(NewsDataProvider.Instance.ContentController);
                attachmentController.AddImagesToContent(contentItem.ContentItemId, images);
            }

            // add terms to content item
            var termController = new TermController();

            foreach (var term in terms)
            {
                termController.AddTermToContent(term, contentItem);
            }
        }
Esempio n. 8
0
        public void UpdateNewsEntry(NewsEntryInfo newsEntry, List <Term> terms, int moduleId, int tabId)
        {
            // TODO: Update value of ContentKey
            // update content item
            newsEntry.ContentItem.ContentTitle = newsEntry.Title;
            newsEntry.ContentItem.Content      = newsEntry.Title;
            newsEntry.ContentItem.ModuleID     = newsEntry.AgentModuleId ?? moduleId;
            newsEntry.ContentItem.TabID        = tabId;
            NewsDataProvider.Instance.ContentController.UpdateContentItem(newsEntry.ContentItem);

            NewsDataProvider.Instance.Update <NewsEntryInfo> (newsEntry);

            // update content item terms
            var termController = new TermController();

            termController.RemoveTermsFromContent(newsEntry.ContentItem);
            foreach (var term in terms)
            {
                termController.AddTermToContent(term, newsEntry.ContentItem);
            }

            CacheHelper.RemoveCacheByPrefix(NewsCacheKeyPrefix);
        }