public HttpResponseMessage Exist(int vocabularyId, int termId, int parentId, string termName)
        {
            var exists = false;

            var controller = new TermController();
            var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.VocabularyId == vocabularyId);

            if (vocabulary != null && !string.IsNullOrEmpty(termName))
            {
                var terms = controller.GetTermsByVocabulary(vocabularyId);
                exists = terms.Any(t => t.Name.Equals(termName.Trim(), StringComparison.InvariantCultureIgnoreCase) && t.TermId != termId && (parentId < 0 || t.ParentTermId == parentId));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, exists));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
        public HttpResponseMessage Search(int vocabularyId, int termId, int parentId, string termName)
        {
            IList <SearchResult> results = new List <SearchResult>();

            var controller = new TermController();
            var vocabulary = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.VocabularyId == vocabularyId);

            if (vocabulary != null && !string.IsNullOrEmpty(termName))
            {
                var terms        = controller.GetTermsByVocabulary(vocabularyId);
                var relatedTerms = terms.Where(t => t.Name.ToLowerInvariant().Contains(termName.Trim().ToLowerInvariant()) && t.TermId != termId && (parentId < 0 || t.ParentTermId == parentId));

                foreach (Term term in relatedTerms)
                {
                    results.Add(new SearchResult()
                    {
                        label = term.Name, value = term.Name
                    });
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, results));
        }
Exemplo n.º 5
0
        public void TermController_GetTermsByVocabulary_Returns_Terms_On_Valid_VocabularyId()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();

            mockDataService.Setup(ds => ds.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1)).Returns(MockHelper.CreateValidTermsReader(Constants.TERM_ValidCountForVocabulary1,
                                                                                                                                            v => Constants.TERM_ValidVocabulary1,
                                                                                                                                            c => Constants.TERM_ValidContent1));
            MockComponentProvider.CreateDataProvider().Setup(c => c.GetProviderPath()).Returns(String.Empty);

            var termController = new TermController(mockDataService.Object);

            //Act
            var terms = termController.GetTermsByVocabulary(Constants.TERM_ValidVocabulary1).ToList();

            //Assert
            Assert.AreEqual(Constants.TERM_ValidCountForVocabulary1, terms.Count);

            for (int i = 0; i < Constants.TERM_ValidCountForVocabulary1; i++)
            {
                Assert.AreEqual(i + Constants.TERM_ValidTermId, terms[i].TermId);
                Assert.AreEqual(ContentTestHelper.GetTermName(i + Constants.TERM_ValidTermId), terms[i].Name);
            }
        }
Exemplo n.º 6
0
        public List <Term> GetTermsByVocabulary(int vocabularyId)
        {
            var vocabulary = _vocabularyController.GetVocabularies().SingleOrDefault(v => v.VocabularyId == vocabularyId);

            return(_termController.GetTermsByVocabulary(vocabularyId).ToList());
        }
Exemplo n.º 7
0
        protected virtual void UpdateTabInfoFromPageSettings(TabInfo tab, PageSettings pageSettings)
        {
            tab.TabName     = pageSettings.Name;
            tab.TabPath     = Globals.GenerateTabPath(tab.ParentId, tab.TabName);
            tab.Title       = pageSettings.Title;
            tab.Description = GetTabDescription(pageSettings);
            tab.KeyWords    = GetKeyWords(pageSettings);
            tab.IsVisible   = pageSettings.IncludeInMenu;
            tab.DisableLink = pageSettings.DisableLink;

            tab.StartDate = pageSettings.StartDate ?? Null.NullDate;
            tab.EndDate   = pageSettings.EndDate ?? Null.NullDate;

            tab.IsSecure = pageSettings.IsSecure;
            tab.TabSettings["AllowIndex"] = pageSettings.AllowIndex;

            tab.SiteMapPriority = pageSettings.SiteMapPriority;
            tab.PageHeadText    = pageSettings.PageHeadText;

            tab.PermanentRedirect = pageSettings.PermanentRedirect;
            tab.Url = GetInternalUrl(pageSettings);

            tab.TabSettings["CacheProvider"] = pageSettings.CacheProvider;
            if (pageSettings.CacheProvider != null)
            {
                tab.TabSettings["CacheDuration"] = pageSettings.CacheDuration;
                if (pageSettings.CacheIncludeExclude.HasValue)
                {
                    if (pageSettings.CacheIncludeExclude.Value)
                    {
                        tab.TabSettings["CacheIncludeExclude"] = "1";
                        tab.TabSettings["IncludeVaryBy"]       = null;
                        tab.TabSettings["ExcludeVaryBy"]       = pageSettings.CacheExcludeVaryBy;
                    }
                    else
                    {
                        tab.TabSettings["CacheIncludeExclude"] = "0";
                        tab.TabSettings["IncludeVaryBy"]       = pageSettings.CacheIncludeVaryBy;
                        tab.TabSettings["ExcludeVaryBy"]       = null;
                    }
                    tab.TabSettings["MaxVaryByCount"] = pageSettings.CacheMaxVaryByCount;
                }
            }

            else
            {
                tab.TabSettings["CacheDuration"]       = null;
                tab.TabSettings["CacheIncludeExclude"] = null;
                tab.TabSettings["IncludeVaryBy"]       = null;
                tab.TabSettings["ExcludeVaryBy"]       = null;
                tab.TabSettings["MaxVaryByCount"]      = null;
            }

            tab.TabSettings["LinkNewWindow"]    = pageSettings.LinkNewWindow;
            tab.TabSettings["CustomStylesheet"] = pageSettings.PageStyleSheet;

            // Tab Skin
            tab.SkinSrc      = GetSkinSrc(pageSettings);
            tab.ContainerSrc = GetContainerSrc(pageSettings);

            if (pageSettings.PageType == "template")
            {
                tab.ParentId = GetTemplateParentId(tab.PortalID);
                tab.IsSystem = true;
            }

            tab.Terms.Clear();
            if (!string.IsNullOrEmpty(pageSettings.Tags))
            {
                tab.Terms.Clear();
                var termController       = new TermController();
                var vocabularyController = Util.GetVocabularyController();
                var vocabulary           = (vocabularyController.GetVocabularies()
                                            .Cast <Vocabulary>()
                                            .Where(v => v.Name == PageTagsVocabulary))
                                           .SingleOrDefault();

                int vocabularyId;
                if (vocabulary == null)
                {
                    var scopeType = Util.GetScopeTypeController().GetScopeTypes().SingleOrDefault(s => s.ScopeType == "Portal");
                    if (scopeType == null)
                    {
                        throw new Exception("Can't create default vocabulary as scope type 'Portal' can't finded.");
                    }

                    vocabularyId = vocabularyController.AddVocabulary(
                        new Vocabulary(PageTagsVocabulary, string.Empty, VocabularyType.Simple)
                    {
                        ScopeTypeId = scopeType.ScopeTypeId,
                        ScopeId     = tab.PortalID
                    });
                }
                else
                {
                    vocabularyId = vocabulary.VocabularyId;
                }

                //get all terms info
                var allTerms     = new List <Term>();
                var vocabularies = from v in vocabularyController.GetVocabularies()
                                   where (v.ScopeType.ScopeType == "Portal" && v.ScopeId == tab.PortalID && !v.Name.Equals("Tags", StringComparison.InvariantCultureIgnoreCase))
                                   select v;
                foreach (var v in vocabularies)
                {
                    allTerms.AddRange(termController.GetTermsByVocabulary(v.VocabularyId));
                }

                foreach (var tag in pageSettings.Tags.Trim().Split(','))
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var term = allTerms.FirstOrDefault(t => t.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
                        if (term == null)
                        {
                            var termId = termController.AddTerm(new Term(tag, string.Empty, vocabularyId));
                            term = termController.GetTerm(termId);
                        }

                        tab.Terms.Add(term);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static List <Term> ToTabTerms(string pageSettingsTags, int tabPortalId)
        {
            var terms = new List <Term>();

            if (string.IsNullOrEmpty(pageSettingsTags))
            {
                return(terms);
            }

            var termController       = new TermController();
            var vocabularyController = Util.GetVocabularyController();
            var vocabulary           = (vocabularyController.GetVocabularies()
                                        .Cast <Vocabulary>()
                                        .Where(v => v.Name == PageTagsVocabulary))
                                       .SingleOrDefault();

            var vocabularyId = Null.NullInteger;

            if (vocabulary == null)
            {
                var scopeType = Util.GetScopeTypeController().GetScopeTypes().SingleOrDefault(s => s.ScopeType == "Portal");
                if (scopeType == null)
                {
                    throw new Exception("Can't create default vocabulary as scope type 'Portal' can't finded.");
                }

                vocabularyId = vocabularyController.AddVocabulary(
                    new Vocabulary(PageTagsVocabulary, string.Empty, VocabularyType.Simple)
                {
                    ScopeTypeId = scopeType.ScopeTypeId,
                    ScopeId     = tabPortalId
                });
            }
            else
            {
                vocabularyId = vocabulary.VocabularyId;
            }

            //get all terms info
            var allTerms     = new List <Term>();
            var vocabularies = from v in vocabularyController.GetVocabularies()
                               where (v.ScopeType.ScopeType == "Portal" && v.ScopeId == tabPortalId && !v.Name.Equals("Tags", StringComparison.InvariantCultureIgnoreCase))
                               select v;

            foreach (var v in vocabularies)
            {
                allTerms.AddRange(termController.GetTermsByVocabulary(v.VocabularyId));
            }

            foreach (var tag in pageSettingsTags.Trim().Split(','))
            {
                if (!string.IsNullOrEmpty(tag))
                {
                    var term = allTerms.FirstOrDefault(t => t.Name.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
                    if (term == null)
                    {
                        var termId = termController.AddTerm(new Term(tag, string.Empty, vocabularyId));
                        term = termController.GetTerm(termId);
                    }

                    terms.Add(term);
                }
            }


            return(terms);
        }