Accounts


List of examples:

Accounts

Creating an account



// Creates a new account object
AccountInfo newAccount = new AccountInfo()
{
    AccountName = "New Account"
};

// Saves the new account to the database
AccountInfo.Provider.Set(newAccount);

> Back to list of examples

Updating accounts



// Gets all accounts whose name starts with 'New'
var accounts = AccountInfo.Provider.Get().WhereStartsWith("AccountName", "New");

// Loops through individual accounts
foreach (AccountInfo account in accounts)
{
    // Updates the account's properties
    account.AccountName = account.AccountName.ToLowerCSafe();

    // Saves the modified account into the database
    AccountInfo.Provider.Set(account);
}

> Back to list of examples

Adding contacts to an account



// Gets the 'New Account' account
AccountInfo account = AccountInfo.Provider.Get()
                                            .WhereEquals("AccountName", "New Account")
                                            .TopN(1)
                                            .FirstOrDefault();

if (account != null)
{
    // Gets all contacts whose last name is 'Smith'
    var contacts = ContactInfo.Provider.Get().WhereEquals("ContactLastName", "Smith");

    // Loops through individual contacts
    foreach (ContactInfo contact in contacts)
    {
        // Creates an object representing the relationship between the account and the contact
        AccountContactInfo accountContact = new AccountContactInfo()
        {
            AccountID = account.AccountID,
            ContactID = contact.ContactID
        };

        // Saves the account-contact relationship to the database
        AccountContactInfo.Provider.Set(accountContact);
    }
}

> Back to list of examples

Removing contacts from an account



// Gets the 'New Account' account
AccountInfo account = AccountInfo.Provider.Get()
                                            .WhereEquals("AccountName", "New Account")
                                            .TopN(1)
                                            .FirstOrDefault();

if (account != null)
{
    // Gets the first contact whose last name is 'Smith'
    ContactInfo contact = ContactInfo.Provider.Get()
                                        .WhereEquals("ContactLastName", "Smith")
                                        .TopN(1)
                                        .FirstOrDefault();

    // Gets the relationship between the contact and the account
    AccountContactInfo accountContact = AccountContactInfo.Provider.Get(account.AccountID, contact.ContactID);

    if (accountContact != null)
    {
        // Removes the contact from the account
        AccountContactInfo.Provider.Delete(accountContact);
    }
}

> Back to list of examples

Deleting an account



// Gets the 'New Account'
AccountInfo deleteAccount = AccountInfo.Provider.Get()
                                            .WhereEquals("AccountName", "New Account")
                                            .TopN(1)
                                            .FirstOrDefault();

if (deleteAccount != null)
{
    // Deletes the account
    AccountInfo.Provider.Delete(deleteAccount);
}

> Back to list of examples

Account statuses

Creating an account status



// Creates a new account status object
AccountStatusInfo newStatus = new AccountStatusInfo()
{
    AccountStatusDisplayName = "New account status",
    AccountStatusName = "NewAccountStatus",
};

// Saves the account status to the database
AccountStatusInfo.Provider.Set(newStatus);

> Back to list of examples

Updating an account status



// Gets the account status
AccountStatusInfo updateStatus = AccountStatusInfo.Provider.Get("NewAccountStatus");

if (updateStatus != null)
{
    // Updates the account status properties
    updateStatus.AccountStatusDisplayName = updateStatus.AccountStatusDisplayName.ToLowerCSafe();

    // Saves the modified account status to the database
    AccountStatusInfo.Provider.Set(updateStatus);
}

> Back to list of examples

Updating multiple account statuses



// Gets all account statuses whose code name starts with 'New'
var statuses = AccountStatusInfo.Provider.Get()
                                            .WhereStartsWith("AccountStatusName","New");

// Loops through individual account statuses
foreach (AccountStatusInfo accountStatus in statuses)
{
    // Updates the account status properties
    accountStatus.AccountStatusDisplayName = accountStatus.AccountStatusDisplayName.ToUpper();

    // Saves the modified account status to the database
    AccountStatusInfo.Provider.Set(accountStatus);
}

> Back to list of examples

Assigning a status to an account



// Gets the 'New Account' account
AccountInfo account = AccountInfo.Provider.Get()
                                            .WhereEquals("AccountName", "New Account")
                                            .TopN(1)
                                            .FirstOrDefault();

// Gets the account status
AccountStatusInfo accountStatus = AccountStatusInfo.Provider.Get("NewAccountStatus");

if ((account != null) && (accountStatus != null))
{
    // Checks that the account doesn't already have the given status
    if (account.AccountStatusID != accountStatus.AccountStatusID)
    {
        // Assigns the status to the account
        account.AccountStatusID = accountStatus.AccountStatusID;

        // Saves the updated account to the database
        AccountInfo.Provider.Set(account);
    }
}

> Back to list of examples

Removing statuses from accounts



// Gets the account status
AccountStatusInfo accountStatus = AccountStatusInfo.Provider.Get("NewAccountStatus");

if (accountStatus != null)
{
    // Gets all accounts that have the specified status
    var accounts = AccountInfo.Provider.Get().WhereEquals("AccountStatusID", accountStatus.AccountStatusID);

    // Loops through the accounts
    foreach (AccountInfo account in accounts)
    {
        // Sets the status to 'None' for each account
        account.AccountStatusID = 0;

        // Saves the updated account to the database
        AccountInfo.Provider.Set(account);
    }
}

> Back to list of examples

Deleting an account status



// Gets the account status
AccountStatusInfo deleteStatus = AccountStatusInfo.Provider.Get("NewAccountStatus");

if (deleteStatus != null)
{
    // Deletes the account status
    AccountStatusInfo.Provider.Delete(deleteStatus);
}

> Back to list of examples

Contact roles for accounts

Creating a contact role



// Creates a new contact role object
ContactRoleInfo newRole = new ContactRoleInfo()
{
    ContactRoleDisplayName = "New role",
    ContactRoleName = "NewContactRole",
};

// Saves the contact role to the database
ContactRoleInfo.Provider.Set(newRole);

> Back to list of examples

Updating a contact role



// Gets the contact role
ContactRoleInfo updateRole = ContactRoleInfo.Provider.Get("NewContactRole");

if (updateRole != null)
{
    // Updates the contact role properties
    updateRole.ContactRoleDisplayName = updateRole.ContactRoleDisplayName.ToLowerCSafe();

    // Saves the modified contact role to the database
    ContactRoleInfo.Provider.Set(updateRole);
}

> Back to list of examples

Updating multiple contact roles



// Gets all contact roles whose code name starts with 'New'
var roles = ContactRoleInfo.Provider.Get().WhereStartsWith("ContactRoleName", "New");

// Loops through individual contact roles
foreach (ContactRoleInfo role in roles)
{
    // Updates the contact role properties
    role.ContactRoleDisplayName = role.ContactRoleDisplayName.ToUpper();

    // Saves the updated contact role to the database
    ContactRoleInfo.Provider.Set(role);
}

> Back to list of examples

Assigning a role to contacts in an account



// Gets the 'New Account' account
AccountInfo account = AccountInfo.Provider.Get()
                                            .WhereEquals("AccountName", "New Account")
                                            .TopN(1)
                                            .FirstOrDefault();

// Gets the contact role
ContactRoleInfo contactRole = ContactRoleInfo.Provider.Get("NewContactRole");

if ((account != null) && (contactRole != null))
{
    // Gets the relationships between the account and all of its contacts
    var accountContactRelationships = AccountContactInfo.Provider.Get().WhereEquals("AccountID", account.AccountID);

    // Loops through the contact-account relationships
    foreach (AccountContactInfo accountContact in accountContactRelationships)
    {
        // Assigns the role to the contact for the specified account
        accountContact.ContactRoleID = contactRole.ContactRoleID;

        // Saves the account-contact relationship to the database
        AccountContactInfo.Provider.Set(accountContact);
    }
}

> Back to list of examples

Deleting a contact role



// Gets the contact role
ContactRoleInfo deleteRole = ContactRoleInfo.Provider.Get("NewContactRole");

if (deleteRole != null)
{
    // Deletes the contact role
    ContactRoleInfo.Provider.Delete(deleteRole);
}

> Back to list of examples