예제 #1
0
        // TODO: Need separate methods to get and update
        public static string Update(DropDownList comboWorkingHours, string workingHours, bool addToVocabulary)
        {
            workingHours = workingHours.Trim();
            var workingHoursNonEmpty = !string.IsNullOrWhiteSpace(workingHours);

            if (comboWorkingHours.SelectedIndex <= 0 || workingHoursNonEmpty)
            {
                // TODO: Shouldn't we try to add term after updating main item?
                if (addToVocabulary && workingHoursNonEmpty)
                {
                    // try add new term to working hours vocabulary
                    var vocCtrl = new VocabularyController();
                    var voc     = vocCtrl.GetVocabularies().SingleOrDefault(v => v.Name == UniversityConfig.Instance.Vocabularies.WorkingHours);
                    if (voc != null)
                    {
                        var termCtrl = new TermController();
                        termCtrl.AddTerm(new Term(workingHours, "", voc.VocabularyId));
                        vocCtrl.ClearVocabularyCache();
                    }
                }

                return(workingHours);
            }

            // else: get working hours from a combo
            return(comboWorkingHours.SelectedItem.Text);
        }