Ejemplo n.º 1
0
        public static void UpdateTerm(this IDivision division, IModelContext modelContext)
        {
            var termName = GetSafeTermName(division.ShortTitle, division.Title);

            try {
                var parentDivision = division.GetParentDivision(modelContext);
                if (division.DivisionTermID != null)
                {
                    var termCtrl = new TermController();
                    var term     = termCtrl.GetTerm(division.DivisionTermID.Value);
                    if (term != null)
                    {
                        term.Name = termName;
                        if (parentDivision != null)
                        {
                            term.ParentTermId = parentDivision.DivisionTermID;
                        }
                        termCtrl.UpdateTerm(term);
                    }
                }
            }
            catch (Exception ex) {
                Exceptions.LogException(new Exception($"Error updating {termName} term.", ex));
            }
        }
Ejemplo n.º 2
0
        public static int?AddOrUpdateTerm(this IDivision division, IModelContext modelContext)
        {
            var vocabularyName = UniversityConfig.Instance.Vocabularies.OrgStructure;
            var vocabulary     = new VocabularyController().GetVocabularies().FirstOrDefault(v => v.Name == vocabularyName);

            if (vocabulary == null)
            {
                Exceptions.LogException(new Exception($"Could not find the {vocabularyName} vocabulary."));
                return(null);
            }

            var termName = GetSafeTermName(division.ShortTitle, division.Title);
            var termCtrl = new TermController();
            var term     = default(Term);

            if (division.DivisionTermID == null)
            {
                term = termCtrl.GetTermsByVocabulary(vocabulary.VocabularyId).FirstOrDefault(t => t.Name == termName);
                if (term != null)
                {
                    Exceptions.LogException(new Exception($"Could not create term {termName} in the {vocabularyName} vocabulary as it already exists."));
                    return(null);
                }

                term = new Term(termName, string.Empty, vocabulary.VocabularyId);
            }
            else
            {
                term      = termCtrl.GetTerm(division.DivisionTermID.Value);
                term.Name = termName;
            }

            var parentDivision = division.GetParentDivision(modelContext);

            if (parentDivision != null)
            {
                term.ParentTermId = parentDivision.DivisionTermID;
            }
            else
            {
                term.ParentTermId = null;
            }

            try {
                if (division.DivisionTermID == null)
                {
                    return(termCtrl.AddTerm(term));
                }

                termCtrl.UpdateTerm(term);
                return(term.TermId);
            }
            catch (Exception ex) {
                Exceptions.LogException(new Exception($"Error creating/updating {termName} term in the vocabulary {vocabularyName}.", ex));
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void TermController_GetTerm_Throws_On_Negative_TermId()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws <ArgumentOutOfRangeException>(() => termController.GetTerm(Null.NullInteger));
        }
Ejemplo n.º 4
0
        public static void DeleteTerm(int termId)
        {
            var termCtrl = new TermController();
            var term     = termCtrl.GetTerm(termId);

            if (term != null)
            {
                termCtrl.DeleteTerm(term);
            }
        }
Ejemplo n.º 5
0
        public string GetUrl(int termId, TermController termController)
        {
            var term = termController.GetTerm(termId);

            if (term != null)
            {
                return(GetUrl(term));
            }

            return(string.Empty);
        }
Ejemplo n.º 6
0
        public void TermController_GetTerm_Calls_DataService()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();

            mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId)).Returns(MockHelper.CreateValidTermReader());
            var termController = new TermController(mockDataService.Object);

            //Act
            Term term = termController.GetTerm(Constants.TERM_ValidTermId);

            //Assert
            mockDataService.Verify(ds => ds.GetTerm(Constants.TERM_ValidTermId));
        }
Ejemplo n.º 7
0
        public void TermController_GetTerm_Returns_Null_On_InValidTermId()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();

            mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_InValidTermId)).Returns(MockHelper.CreateEmptyTermReader());

            var termController = new TermController(mockDataService.Object);

            //Act
            Term term = termController.GetTerm(Constants.TERM_InValidTermId);

            //Assert
            Assert.IsNull(term);
        }
Ejemplo n.º 8
0
        public void TermController_GetTerm_Returns_Term_On_Valid_TermId()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();

            mockDataService.Setup(ds => ds.GetTerm(Constants.TERM_ValidTermId)).Returns(MockHelper.CreateValidTermReader());

            var termController = new TermController(mockDataService.Object);

            //Act
            var term = termController.GetTerm(Constants.TERM_ValidTermId);

            //Assert
            Assert.AreEqual(Constants.TERM_ValidTermId, term.TermId);
            Assert.AreEqual(Constants.TERM_ValidName, term.Name);
        }
Ejemplo n.º 9
0
        // TODO: Can use IList or IEnumerable here
        public List <Term> GetSelectedTerms(ListControl listControl)
        {
            var termCtrl      = new TermController();
            var selectedTerms = new List <Term> ();

            foreach (ListItem item in listControl.Items)
            {
                if (item.Selected)
                {
                    var term = termCtrl.GetTerm(int.Parse(item.Value));
                    if (term != null)
                    {
                        selectedTerms.Add(term);
                    }
                }
            }

            return(selectedTerms);
        }
Ejemplo n.º 10
0
        public void ImportModule(int ModuleID, string Content, string Version, int UserID)
        {
            XmlReader xmlReader = null;

            var moduleController = new ModuleController();
            var module           = moduleController.GetModule(ModuleID);

            try {
                var xmlSerializer = new XmlSerializer(typeof(List <XmlNewsEntryInfo>));
                using (xmlReader = XmlReader.Create(new StringReader(Content))) {
                    // deserialize
                    var xmlNewsEntries = (List <XmlNewsEntryInfo>)xmlSerializer.Deserialize(xmlReader);
                    xmlReader.Close();

                    var termController = new TermController();

                    // add news entries
                    foreach (var xmlNewsEntry in xmlNewsEntries)
                    {
                        // get news entry and reset ids
                        var newsEntry = xmlNewsEntry.GetNewsEntryInfo();
                        newsEntry.EntryId       = 0;
                        newsEntry.EntryTextId   = null;
                        newsEntry.AgentModuleId = ModuleID;
                        newsEntry.ContentItemId = 0;
                        newsEntry.PortalId      = module.PortalID;

                        // get terms by ids
                        var terms = new List <Term> ();
                        foreach (var termId in xmlNewsEntry.TermIds)
                        {
                            var term = termController.GetTerm(termId);
                            if (term != null)
                            {
                                terms.Add(term);
                            }
                        }

                        // get images by ids
                        var images = new List <IFileInfo> ();
                        foreach (var imageFileId in xmlNewsEntry.ImageFileIds)
                        {
                            var image = FileManager.Instance.GetFile(imageFileId);
                            if (image != null)
                            {
                                images.Add(image);
                            }
                        }

                        // add news entry
                        NewsRepository.Instance.AddNewsEntry(newsEntry, terms, images, ModuleID, module.TabID);
                    }
                }
            }
            catch (Exception ex) {
                var logController = new EventLogController();

                var logInfo = new LogInfo {
                    Exception   = new ExceptionInfo(ex),
                    LogTypeKey  = EventLogController.EventLogType.ADMIN_ALERT.ToString(),
                    LogUserID   = -1, // superuser
                    LogPortalID = module.PortalID
                };

                logInfo.AddProperty("R7.News.Agent", "Cannot import module");
                logController.AddLog(logInfo);
            }
            finally {
                if (xmlReader != null)
                {
                    xmlReader.Close();
                }
            }
        }
Ejemplo n.º 11
0
 public Term GetTerm(int termId)
 {
     return(_termController.GetTerm(termId));
 }
Ejemplo n.º 12
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);
                    }
                }
            }
        }
Ejemplo n.º 13
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);
        }