コード例 #1
0
        [ValidateHttpAntiForgeryToken]  // This attribute secures the method with Anti-CSRF
        public IHttpActionResult EditTags(string id, string[] tagsidlist)
        {
            // todo move to sitecore helper
            Sitecore.Data.Database db = Sitecore.Context.Database;
            Item item = db.GetItem(new Sitecore.Data.ID(id));

            if (item.Fields[TAGS] == null)
            {
                return(NotFound());
            }

            MultilistField tags = item.Fields[TAGS];


            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();

                tags.Value = string.Empty;

                foreach (var str in tagsidlist)
                {
                    tags.Add(str);
                }

                try
                {
                    item[TAGS] = tags.ToString();
                }
                finally
                {
                    item.Editing.EndEdit();
                }
            }

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }