/// <summary>
        /// The item that is passed to this method will now be made into a Bucket and all items under it will be automatically organised and hidden.
        /// </summary>
        /// <param name="item">The item that is being turned into a Bucket</param>
        public static void AddSearchTabToItem(Item item)
        {
            MultilistField editors = item.Fields["__Editors"];

            using (new EditContext(item, SecurityCheck.Disable))
            {
                if (!editors.Items.Contains(Constants.SearchEditor))
                {
                    var tempEditors = editors.GetItems();
                    tempEditors.ToList().ForEach(tempEditor => editors.Remove(tempEditor.ID.ToString()));
                    editors.Add(Constants.SearchEditor);
                    tempEditors.ToList().ForEach(tempEditor => editors.Add(tempEditor.ID.ToString()));
                }
            }
        }
        public static IEnumerable <Item> AddIdToMultilist(this Item hostItem, string fieldName, string newId, bool checkSecurity = false)
        {
            Assert.IsNotNull(hostItem, "hostItem cannot be null");
            Assert.IsNotNullOrEmpty(fieldName, "fieldName cannot be null or empty");
            Assert.IsNotNullOrEmpty(newId, "newId cannot be null or empty");
            Assert.IsTrue(ID.IsID(newId), "newId is not a proper GUID");

            var field      = hostItem.Fields[fieldName];
            var targetItem = hostItem.Database.GetItem(newId);

            if (field != null && field.IsOfType <MultilistField>())
            {
                var state = SecurityState.Enabled;
                if (!checkSecurity)
                {
                    state = SecurityState.Disabled;
                }

                using (new SecurityStateSwitcher(state))
                {
                    using (new EditContext(hostItem))
                    {
                        MultilistField mlField = field;
                        mlField.Add(targetItem.ID.ToString());
                        return(mlField.GetItems());
                    }
                }
            }

            return(new Item[0]);
        }
예제 #3
0
        public bool Build(CommentViewModel viewModel)
        {
            try
            {
                var comment = Mapper.Map <Comment>(viewModel);
                var result  = _commentRepository.Create(comment);
                if (!result)
                {
                    ModelErrors.Add(_commentRepository.RepositoryErrors.LastOrDefault());
                    return(false);
                }

                using (new SecurityDisabler())
                {
                    var item = _context.GetItem <Item>(viewModel.ArticleId);
                    item.Editing.BeginEdit();
                    MultilistField comments = new MultilistField(item.Fields["Comments"]);
                    comments.Add(comment.Id.ToString());
                    item.Editing.EndEdit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ModelErrors.Add(ex);
                return(false);
            }
        }
예제 #4
0
 public static void AddSearchTab(Item contextItem, MultilistField editors)
 {
     using (new EditContext(contextItem, SecurityCheck.Disable))
     {
         if (!editors.Items.Contains(Constants.SearchEditor))
         {
             editors.Add(Constants.SearchEditor);
         }
     }
 }
예제 #5
0
 public static void AddSearchTab(Item contextItem, MultilistField editors)
 {
     using (new EditContext(contextItem, SecurityCheck.Disable))
     {
         if (!editors.Items.Contains(Constants.SearchEditor))
         {
             editors.Add(Constants.SearchEditor);
         }
     }
 }
        public void CreateBucket(BucketArgs args)
        {
            Event.RaiseEvent("item:bucketing:starting", args, this);
            var            contextItem = args.Item;
            MultilistField editors     = contextItem.Fields["__Editors"];

            using (new EditContext(contextItem, SecurityCheck.Disable))
            {
                if (!editors.Items.Contains(Util.Constants.SearchEditor))
                {
                    var tempEditors = editors.GetItems();
                    tempEditors.ToList().ForEach(tempEditor => editors.Remove(tempEditor.ID.ToString()));
                    editors.Add(Util.Constants.SearchEditor);
                    tempEditors.ToList().ForEach(tempEditor => editors.Add(tempEditor.ID.ToString()));
                }
            }

            Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute(Util.Constants.BucketingText, Util.Constants.BucketingProgressText, Images.GetThemedImageSource("Business/16x16/chest_add.png"), this.StartProcess, new object[] { contextItem });
            Context.ClientPage.SendMessage(this, "item:load(id=" + contextItem.ID + ")");
            Context.ClientPage.SendMessage(this, "item:refreshchildren(id=" + contextItem.Parent.ID + ")");
        }
예제 #7
0
        private void SwapMultilistFieldValue(Item item, MultilistField field, ID targetItemId, ID newItemId)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(field, "field");
            Assert.ArgumentNotNull(targetItemId, "targetItemId");
            Assert.ArgumentNotNull(newItemId, "newItemId");

            using (new Sitecore.Data.Items.EditContext(item))
            {
                field.Remove(targetItemId.ToString());
                field.Add(newItemId.ToString());
            }
        }
예제 #8
0
        /// <summary>
        /// Set value for Checklist, Multilist, Treelist, and Version Link field types
        /// </summary>
        /// <param name="field">Sitecore Field</param>
        /// <param name="value">Sitecore Item, IEnumerable of Item, IEnumerable of Path or IDs as string, ID as GUID or Sitecore.Data.ID, Path or ID as string</param>
        public static void SetListValue(Field field, object value)
        {
            MultilistField thisField = (MultilistField)field;

            if (value is Item)
            {
                thisField.Value = ((Item)value).ID.ToString();
            }
            else if (value is IEnumerable <Item> )
            {
                thisField.Value = string.Join("|", ((IEnumerable <Item>)value).Select(i => i.ID.ToString()));
            }
            else if (value is IEnumerable <string> )            // assume string is path or guid
            {
                thisField.Value = string.Empty;                 // clear value for add
                foreach (var val in (IEnumerable <string>)value)
                {
                    Item item = field.Database.GetItemFromValue(val);
                    if (item != null)
                    {
                        thisField.Add(item.ID.ToString());
                    }
                }
                thisField.Value = string.Join("|", (IEnumerable <string>)value);
            }
            else if (value is Guid || value is SC.Data.ID)
            {
                thisField.Value = value.ToString();
            }
            else if (value is string)
            {
                string val = value.ToString().ToUpper();                        // fixes "Item not in selection" mismatch due to lowercase
                if (val.Contains(','))
                {
                    thisField.Value = val.Replace(',', '|');
                }
                else if (val.Contains('|'))
                {
                    thisField.Value = val;
                }
                else
                {
                    Item item = field.Database.GetItemFromValue(value);
                    if (item != null)
                    {
                        thisField.Value = item.ID.ToString();
                    }
                }
            }
        }
예제 #9
0
        public void TagContent(Item contentItem, IEnumerable <Guid> related)
        {
            MultilistField field = contentItem.Fields[Constants.Fields.RetatedItems];

            contentItem.Editing.BeginEdit();

            field.Value = "";
            foreach (Guid tag in related)
            {
                if (ID.TryParse(tag, out var result) && !field.TargetIDs.Contains(result))
                {
                    field.Add(result.ToString());
                }
            }
            contentItem.Editing.EndEdit();
        }
예제 #10
0
        protected override void ProcessTemplateItem(TemplateItem templateItem)
        {
            var innerItem = templateItem.InnerItem;

            if (ShouldProcess(innerItem.GetProviderPath(), $"Add base template(s) '{TemplateItem.Select(t => t.InnerItem).GetProviderPaths()}'"))
            {
                MultilistField baseTemplateField = innerItem.Fields[Sitecore.FieldIDs.BaseTemplate];

                innerItem.Editing.BeginEdit();

                foreach (var template in TemplateItem)
                {
                    // Check if base template already exists, if it does than there's nothing to do.
                    if (!baseTemplateField.Contains(template.ID.ToString()))
                    {
                        baseTemplateField.Add(template.ID.ToString());
                    }
                }

                innerItem.Editing.EndEdit();
            }
        }
예제 #11
0
        private void SetFields(Item item)
        {
            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();
                foreach (var f in _fields)
                {
                    item.Fields[f.Key].Value = f.Value;
                }
                ;

                foreach (var f in _multiListfields)
                {
                    MultilistField mf = item.Fields[f.Key];
                    foreach (var v in f.Value)
                    {
                        mf.Add(v.ID.ToString());
                    }
                }
                item.Editing.EndEdit();
            }
        }
예제 #12
0
        /// <summary>
        /// Adds a Sitecore Id to a Multilist Field
        /// <para>All parameters are required.</para>
        /// </summary>
        /// <param name="item">Context Item</param>
        /// <param name="fieldId">Multilist Field</param>
        /// <param name="value">Value to add to the multilist field</param>
        private static void AddToMultiField(Item item, ID fieldId, ID value)
        {
            if (item == null || fieldId.IsNull || value.IsNull)
            {
                return;
            }

            MultilistField multiListField = item.Fields[fieldId];

            if (multiListField == null)
            {
                return;
            }

            using (new SecurityDisabler())
            {
                using (new EditContext(item))
                {
                    multiListField.Add(value.ToString());
                }
            }
        }
예제 #13
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)));
        }
예제 #14
0
        private void UpdateFields(TriggerDetail entity, Item triggerItem)
        {
            triggerItem.Fields["Trigger Key"].Value = entity.TriggerKey;
            DateField startTimeField = triggerItem.Fields["Start Time"];

            if (startTimeField != null)
            {
                startTimeField.Value = Sitecore.DateUtil.ToIsoDate(entity.StartTime);
            }
            triggerItem.Fields["Start Time"].Value = DateUtil.ToIsoDate(entity.StartTime);
            if (entity.EndTime != null || entity.EndTime != DateTime.MinValue)
            {
                triggerItem.Fields["End Time"].Value = DateUtil.ToIsoDate(entity.EndTime);
            }
            else
            {
                triggerItem.Fields["End Time"].Value = "";
            }

            triggerItem.Fields["Schedule Type"].Value   = entity.ScheduleType;
            triggerItem.Fields["Day of Month"].Value    = entity.DayOfMonth.ToString();
            triggerItem.Fields["Repeat Count"].Value    = entity.RepeatCount.ToString();
            triggerItem.Fields["Repeat Interval"].Value = entity.RepeatInterval.ToString();
            triggerItem.Fields["Cron Expression"].Value = entity.CronExpression;
            MultilistField daysOfWeeks = triggerItem.Fields["Days Of Week"];

            Item[] selectedDays = daysOfWeeks.GetItems();
            for (int x = 0; x < selectedDays.Length; x++)
            {
                daysOfWeeks.Remove(selectedDays[x].ID.ToString());
            }
            for (int i = 0; i < entity.DaysOfWeeks.Count; i++)
            {
                daysOfWeeks.Add(entity.DaysOfWeeks[i].itemId);
            }
        }
예제 #15
0
            public void Process(Instance item)
            {
                counter++;
                if (counter % 1000 == 0)
                {
                    Sitecore.Diagnostics.Log.Info("---> Created: " + counter, this);
                }
                var place = placesFolder.Add(ItemUtil.ProposeValidItemName(item.Label), placeTemplateId);

                place.Editing.BeginEdit();

                var categoriesField = new MultilistField(place.Fields["categories"]);

                foreach (var category in item.Categories)
                {
                    categoriesField.Add(GetCategory(category));
                }
                place["id"]          = item.ID;
                place["label"]       = item.Label;
                place["description"] = item.Description;
                place["point"]       = (item.Point != "" && item.Point != "NULL") ? item.Point : "";

                place.Editing.EndEdit();
            }
예제 #16
0
        /// <summary>
        ///     Sets MultilistField
        /// </summary>
        /// <param name="item"></param>
        /// <param name="sitecoreFieldName"></param>
        /// <param name="sitecoreValue"></param>
        public void AddToMultiListField(BaseItem item, string sitecoreFieldName, string sitecoreValue)
        {
            MultilistField multilistField = item.Fields[sitecoreFieldName];

            multilistField?.Add(sitecoreValue);
        }