Esempio n. 1
0
        private OptionItemPart GetOrCreateTerm(OptionItemEntry entry, int taxonomyId, OptionSetField field)
        {
            var term = entry.Id > 0 ? _optionSetService.GetOptionItem(entry.Id) : default(OptionItemPart);

            if (term == null)
            {
                var settings = field.PartFieldDefinition.Settings.GetModel <OptionSetFieldSettings>();

                if (!Services.Authorizer.Authorize(Permissions.CreateTerm))
                {
                    Services.Notifier.Error(T("You're not allowed to create new terms for this taxonomy"));
                    return(null);
                }

                var taxonomy = _optionSetService.GetOptionSet(taxonomyId);
                term            = _optionSetService.NewTerm(taxonomy);
                term.Container  = taxonomy.ContentItem;
                term.Name       = entry.Name.Trim();
                term.Selectable = true;

                Services.ContentManager.Create(term, VersionOptions.Published);
                Services.Notifier.Information(T("The {0} term has been created.", term.Name));
            }

            return(term);
        }
Esempio n. 2
0
        // DELETE api/<controller>/5
        public void Delete(int id)
        {
            var optionItem = _optionSetService.GetOptionItem(id);

            _optionSetService.DeleteOptionItem(optionItem);
        }