예제 #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);
        }
예제 #2
0
        // POST api/<controller>
        public HttpResponseMessage Post(OptionItemEntry optionItem)
        {
            var itemPart = Services.ContentManager.New <OptionItemPart>("OptionItem");

            itemPart.OptionSetId = optionItem.OptionSetId;
            itemPart.Name        = optionItem.Name;
            itemPart.Selectable  = optionItem.Selectable;
            itemPart.Weight      = optionItem.Weight;
            return(_optionSetService.CreateTerm(itemPart)
                ? Request.CreateResponse(HttpStatusCode.OK)
               : Request.CreateResponse(HttpStatusCode.Conflict, T("The term {0} already exists in this optionset", itemPart.Name)));
        }
예제 #3
0
        public bool EditOptionItem(OptionItemEntry newItem)
        {
            var oldItem = _contentManager.Get(newItem.Id).As <OptionItemPart>();

            if (oldItem == null)
            {
                return(false);
            }
            oldItem.Name       = newItem.Name;
            oldItem.Selectable = newItem.Selectable;
            oldItem.Weight     = newItem.Weight;
            return(true);
        }
예제 #4
0
 // PUT api/<controller>/...
 public HttpResponseMessage Put(OptionItemEntry optionItem)
 {
     return(_optionSetService.EditOptionItem(optionItem) ?
            Request.CreateResponse(HttpStatusCode.OK) : Request.CreateResponse(HttpStatusCode.NotFound));
 }