public void SaveTerm(object sender, EventArgs e)
        {
            //First Bind the term so we can get the current values from the View
            View.BindTerm(View.Model.Term, View.Model.Terms, IsHeirarchical, true, IsEditEnabled);

            var result = Validator.ValidateObject(View.Model.Term);

            if (result.IsValid)
            {
                if (View.Model.Term.TermId == Null.NullInteger)
                {
                    TermController.AddTerm(View.Model.Term);
                }
                else
                {
                    TermController.UpdateTerm(View.Model.Term);
                }

                RefreshTerms();
            }
            else
            {
                ShowMessage("TermValidationError", ModuleMessage.ModuleMessageType.RedError);
            }
        }
Ejemplo n.º 2
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.º 3
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.º 4
0
        public void TermController_UpdateTerm_Throws_On_Null_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            //Act, Arrange
            Assert.Throws <ArgumentNullException>(() => termController.UpdateTerm(null));
        }
Ejemplo n.º 5
0
        public void TermController_UpdateTerm_Throws_On_Negative_VocabularyId()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidSimpleTerm(Null.NullInteger);

            //Act, Arrange
            Assert.Throws <ArgumentOutOfRangeException>(() => termController.UpdateTerm(term));
        }
Ejemplo n.º 6
0
        public void TermController_UpdateTerm_Throws_On_Invalid_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

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

            term.Name = Constants.TERM_InValidName;

            //Act, Arrange
            Assert.Throws <ArgumentOutOfRangeException>(() => termController.UpdateTerm(term));
        }
Ejemplo n.º 7
0
        public void UpdateTerm(Term term)
        {
            var result = _validator.ValidateObject(term);

            if (result.IsValid)
            {
                _termController.UpdateTerm(term);
            }
            else
            {
                throw new TermValidationException();
            }
        }
Ejemplo n.º 8
0
        public void TermController_UpdateTerm_Clears_Term_Cache_On_Valid_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

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

            term.TermId = Constants.TERM_UpdateTermId;
            term.Name   = Constants.TERM_UpdateName;
            term.Weight = Constants.TERM_UpdateWeight;

            //Act
            termController.UpdateTerm(term);

            //Assert
            mockCache.Verify(cache => cache.Remove(String.Format(Constants.TERM_CacheKey, Constants.VOCABULARY_ValidVocabularyId)));
        }
Ejemplo n.º 9
0
        public void TermController_UpdateTerm_Should_Call_DataService_UpdateHeirarchicalTerm_If_Term_Is_Heirarchical_Term()
        {
            //Arrange
            var mockDataService = new Mock <IDataService>();
            var termController  = new TermController(mockDataService.Object);

            Term term = ContentTestHelper.CreateValidHeirarchicalTerm(Constants.VOCABULARY_HierarchyVocabularyId, Constants.TERM_ValidParentTermId);

            term.TermId = Constants.TERM_UpdateTermId;
            term.Name   = Constants.TERM_UpdateName;
            term.Weight = Constants.TERM_UpdateWeight;

            // Act
            termController.UpdateTerm(term);

            // Assert
            mockDataService.Verify(ds => ds.UpdateHeirarchicalTerm(term, UserController.Instance.GetCurrentUserInfo().UserID));
        }