Contacts


List of examples:

Dependency injection

Initialize required services

C#


// Initializes all services and provider classes used within
// the API examples on this page using dependency injection.
private readonly IInfoProvider<ContactInfo> contactInfoProvider;

public ContactsServices(IInfoProvider<ContactInfo> contactInfoProvider)
{
    this.contactInfoProvider = contactInfoProvider;
}

> Back to list of examples

Contacts

Get the current contact

C#


// Gets the contact related to the currently processed request
ContactInfo currentContact = ContactManagementContext.CurrentContact;

> Back to list of examples

Create contacts

C#


// Creates a new contact object
ContactInfo newContact = new ContactInfo()
{
    ContactLastName = "Smith",
    ContactFirstName = "John",

    // Enables activity tracking for the new contact
    ContactMonitored = true
};

// Saves the contact to the database
contactInfoProvider.Set(newContact);

> Back to list of examples

Update contacts

C#


// Gets the first contact whose last name is 'Smith'
ContactInfo updateContact = contactInfoProvider.Get()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .TopN(1)
                                    .FirstOrDefault();

if (updateContact != null)
{
    // Updates the contact's properties
    updateContact.ContactCompanyName = "Company Inc.";

    // Saves the updated contact to the database
    contactInfoProvider.Set(updateContact);
}

> Back to list of examples

Update multiple contacts

C#


// Gets all contacts whose last name is 'Smith'
var contacts = contactInfoProvider.Get()
                                  .WhereEquals("ContactLastName", "Smith");

// Loops through individual contacts
foreach (ContactInfo contact in contacts)
{
    // Updates the properties of the contact
    contact.ContactCompanyName = "Company Inc.";

    // Saves the updated contact to the database
    contactInfoProvider.Set(contact);
}

> Back to list of examples

Delete contacts

C#


// Gets the first contact whose last name is 'Smith'
ContactInfo deleteContact = contactInfoProvider.Get()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .TopN(1)
                                    .FirstOrDefault();

if (deleteContact != null)
{
    // Deletes the contact
    contactInfoProvider.Delete(deleteContact);
}

> Back to list of examples