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)); } }
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); }
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)); }
public static void DeleteTerm(int termId) { var termCtrl = new TermController(); var term = termCtrl.GetTerm(termId); if (term != null) { termCtrl.DeleteTerm(term); } }
public string GetUrl(int termId, TermController termController) { var term = termController.GetTerm(termId); if (term != null) { return(GetUrl(term)); } return(string.Empty); }
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)); }
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); }
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); }
// 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); }
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(); } } }
public Term GetTerm(int termId) { return(_termController.GetTerm(termId)); }
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); } } } }
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); }