Skip to content

Instantly share code, notes, and snippets.

@gillissm
Created February 10, 2016 21:08
Show Gist options
  • Save gillissm/ceeb0179a4de1c1a860e to your computer and use it in GitHub Desktop.
Save gillissm/ceeb0179a4de1c1a860e to your computer and use it in GitHub Desktop.
Step 4: Retrieving from the Contact Facet
switch (this.Name.ToLower())
{
case "first name":
retValue = Tracker.Current.Contact.GetFacet<IContactPersonalInfo>("Personal").FirstName;
break;
case "last name":
retValue = Tracker.Current.Contact.GetFacet<IContactPersonalInfo>("Personal").Surname;
break;
case "email":
IContactEmailAddresses ea = Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails");
if (!string.IsNullOrWhiteSpace(ea.Preferred) && ea.Entries.Contains(ea.Preferred))
{
retValue = ea.Entries[ea.Preferred].SmtpAddress;
}
else if (ea.Entries.Keys.Any())
{
retValue = ea.Entries[ea.Entries.Keys.First()].SmtpAddress;
}
break;
case "city":
IContactAddresses ca = Tracker.Current.Contact.GetFacet<IContactAddresses>("Addresses");
if (!string.IsNullOrWhiteSpace(ca.Preferred) && ca.Entries.Contains(ca.Preferred))
{
retValue = ca.Entries[ca.Preferred].City;
}
else if (ca.Entries.Keys.Any())
{
retValue = ca.Entries[ca.Entries.Keys.First()].City;
}
break;
case "phone":
IContactPhoneNumbers pn = Tracker.Current.Contact.GetFacet<IContactPhoneNumbers>("Phone Numbers");
if (!string.IsNullOrWhiteSpace(pn.Preferred) && pn.Entries.Contains(pn.Preferred))
{
retValue = string.Format("{0}-{1}", pn.Entries[pn.Preferred].CountryCode, pn.Entries[pn.Preferred].Number);
}
else if (pn.Entries.Keys.Any())
{
string firstKey = pn.Entries.Keys.First();
retValue = string.Format("{0}-{1}", pn.Entries[firstKey].CountryCode, pn.Entries[firstKey].Number);
}
break;
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment