Example #1
0
        /// <summary>
        /// Updates the links.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="currentItem">The current item.</param>
        /// <param name="mapping">The mapping.</param>
        private void UpdateLinks(Item root, Item currentItem, IDictionary <ID, string> mapping)
        {
            using (new EditContext(currentItem))
            {
                foreach (Field field in currentItem.Fields)
                {
                    ListString references = new ListString(field.Value);

                    if (references.All(ID.IsID))
                    {
                        ListString updatedReferences = new ListString();

                        foreach (string reference in references)
                        {
                            ID key = ID.Parse(reference);
                            if (mapping.ContainsKey(key))
                            {
                                updatedReferences.Add(root.Axes.GetDescendant(mapping[key]).ID.ToString());
                            }
                            else
                            {
                                updatedReferences.Add(reference);
                            }
                        }

                        field.Value = updatedReferences.ToString();
                    }
                }
            }

            foreach (Item child in currentItem.Children)
            {
                this.UpdateLinks(root, child, mapping);
            }
        }
    /// <summary>
    /// Updates the links.
    /// </summary>
    /// <param name="root">The root.</param>
    /// <param name="currentItem">The current item.</param>
    /// <param name="mapping">The mapping.</param>
    private void UpdateLinks(Item root, Item currentItem, IDictionary<ID, string> mapping)
    {
      using (new EditContext(currentItem))
      {
        foreach (Field field in currentItem.Fields)
        {
          ListString references = new ListString(field.Value);

          if (references.All(ID.IsID))
          {
            ListString updatedReferences = new ListString();
            
            foreach (string reference in references)
            {
              ID key = ID.Parse(reference);
              if (mapping.ContainsKey(key))
              {
                updatedReferences.Add(root.Axes.GetDescendant(mapping[key]).ID.ToString());
              }
              else
              {
                updatedReferences.Add(reference);
              }
            }

            field.Value = updatedReferences.ToString();
          }
        }
      }

      foreach (Item child in currentItem.Children)
      {
        this.UpdateLinks(root, child, mapping);
      }
    }