Last active
May 28, 2017 16:48
-
-
Save hishaamn/89270570df14cbd948faab9c519abb8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void TagProfile(TrackingField trackingField, Item item) | |
{ | |
var trackingValue = item.Fields["__Tracking"].Value; | |
var editorial = trackingField.Profiles.FirstOrDefault(p => p.Name.Equals("Editorial")); | |
if (editorial != null) | |
{ | |
var editorialProfileItem = new ProfileItem(editorial.GetProfileItem()); | |
var presetInfo = GetProfileCard(editorialProfileItem); | |
var dictionary = new Dictionary<string, float>(); | |
var presetCount = 100 / presetInfo.Count; | |
foreach (var info in presetInfo) | |
{ | |
dictionary.Add(info.Key, presetCount); | |
} | |
editorial.SaveToField = true; | |
editorial.Presets = dictionary; | |
SetProfileKeys(editorial, editorialProfileItem); | |
TrackingField.UpdateKeyValues(editorial); | |
} | |
documents = string.IsNullOrEmpty(trackingValue) ? new XDocument(new XElement("tracking")) : XDocument.Parse(trackingValue); | |
XDocument document = documents; | |
XElement xelement1 = document.Element("tracking"); | |
if (xelement1 == null) | |
{ | |
xelement1 = new XElement("tracking"); | |
document.Add(xelement1); | |
} | |
List<XElement> list = xelement1.Elements("profile").ToList(); | |
foreach (XElement t in list) | |
{ | |
t.Remove(); | |
} | |
foreach (XElement xelement2 in trackingField.Profiles.Where(profile => profile.SaveToField).Select(profile => profile.ToXElement())) | |
xelement1.Add(xelement2); | |
using (new SecurityDisabler()) | |
{ | |
item.Editing.BeginEdit(); | |
item.Fields["__Tracking"].Value = document.ToString(); | |
item.Editing.EndEdit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment