/CMSAPIExamples/Code/OnlineMarketing/ContactManagement/Default.aspx.cs

https://bitbucket.org/kudutest2/kenticogit · C# · 1421 lines · 740 code · 324 blank · 357 comment · 92 complexity · d76e2bfdab4a156fd9f6763983f46d8c MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Linq;
  4. using CMS.GlobalHelper;
  5. using CMS.UIControls;
  6. using CMS.CMSHelper;
  7. using CMS.SiteProvider;
  8. using CMS.DataEngine;
  9. using CMS.OnlineMarketing;
  10. using CMS.SettingsProvider;
  11. using CMS.WebAnalytics;
  12. [Title(Text = "Contact management", ImageUrl = "Objects/OM_ContactManagement/object.png")]
  13. public partial class CMSAPIExamples_Code_Modules_ContactManagement_Default : CMSAPIExamplePage
  14. {
  15. #region "Initialization"
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. // Contact role
  19. this.apiCreateContactRole.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateContactRole);
  20. this.apiGetAndUpdateContactRole.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateContactRole);
  21. this.apiGetAndBulkUpdateContactRoles.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateContactRoles);
  22. this.apiDeleteContactRole.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteContactRole);
  23. // Contact status
  24. this.apiCreateContactStatus.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateContactStatus);
  25. this.apiGetAndUpdateContactStatus.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateContactStatus);
  26. this.apiGetAndBulkUpdateContactStatuses.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateContactStatuses);
  27. this.apiDeleteContactStatus.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteContactStatus);
  28. // Account status
  29. this.apiCreateAccountStatus.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateAccountStatus);
  30. this.apiGetAndUpdateAccountStatus.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateAccountStatus);
  31. this.apiGetAndBulkUpdateAccountStatuses.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateAccountStatuses);
  32. this.apiDeleteAccountStatus.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteAccountStatus);
  33. // Contact
  34. this.apiCreateContact.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateContact);
  35. this.apiGetAndUpdateContact.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateContact);
  36. this.apiGetAndBulkUpdateContacts.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateContacts);
  37. this.apiDeleteContact.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteContact);
  38. // Contact status
  39. this.apiAddContactStatusToContact.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddContactStatusToContact);
  40. this.apiRemoveContactStatusFromContact.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveContactStatusFromContact);
  41. // Contact membership
  42. this.apiAddMembership.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddMembership);
  43. this.apiRemoveMembership.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveMembership);
  44. // Contact IP address
  45. this.apiAddIPAddress.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddIPAddress);
  46. this.apiRemoveIPAddress.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveIPAddress);
  47. // Contact user agent
  48. this.apiAddUserAgent.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddUserAgent);
  49. this.apiRemoveUserAgent.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveUserAgent);
  50. // Account
  51. this.apiCreateAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateAccount);
  52. this.apiGetAndUpdateAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateAccount);
  53. this.apiGetAndBulkUpdateAccounts.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateAccounts);
  54. this.apiDeleteAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteAccount);
  55. // Account status
  56. this.apiAddAccountStatusToAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddAccountStatusToAccount);
  57. this.apiRemoveAccountStatusFromAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveAccountStatusFromAccount);
  58. // Account contacts
  59. this.apiAddContactToAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddContactToAccount);
  60. this.apiRemoveContactFromAccount.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveContactFromAccount);
  61. // Contact group
  62. this.apiCreateContactGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateContactGroup);
  63. this.apiGetAndUpdateContactGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateContactGroup);
  64. this.apiGetAndBulkUpdateContactGroups.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateContactGroups);
  65. this.apiDeleteContactGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteContactGroup);
  66. // Contact in contact group
  67. this.apiAddContactToGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddContactToGroup);
  68. this.apiRemoveContactFromGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveContactFromGroup);
  69. // Account in contact group
  70. this.apiAddAccountToGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(AddAccountToGroup);
  71. this.apiRemoveAccountFromGroup.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(RemoveAccountFromGroup);
  72. // Activity
  73. this.apiCreateActivity.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateActivity);
  74. this.apiGetAndUpdateActivity.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateActivity);
  75. this.apiGetAndBulkUpdateActivities.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateActivities);
  76. this.apiDeleteActivity.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteActivity);
  77. }
  78. #endregion
  79. #region "Mass actions"
  80. /// <summary>
  81. /// Runs all creating and managing examples.
  82. /// </summary>
  83. public override void RunAll()
  84. {
  85. base.RunAll();
  86. // Contact role
  87. this.apiCreateContactRole.Run();
  88. this.apiGetAndUpdateContactRole.Run();
  89. this.apiGetAndBulkUpdateContactRoles.Run();
  90. // Contact status
  91. this.apiCreateContactStatus.Run();
  92. this.apiGetAndUpdateContactStatus.Run();
  93. this.apiGetAndBulkUpdateContactStatuses.Run();
  94. // Account status
  95. this.apiCreateAccountStatus.Run();
  96. this.apiGetAndUpdateAccountStatus.Run();
  97. this.apiGetAndBulkUpdateAccountStatuses.Run();
  98. // Contact
  99. this.apiCreateContact.Run();
  100. this.apiGetAndUpdateContact.Run();
  101. this.apiGetAndBulkUpdateContacts.Run();
  102. // Contact with contact status
  103. this.apiAddContactStatusToContact.Run();
  104. // Contact memebership
  105. this.apiAddMembership.Run();
  106. // Contact IP address
  107. this.apiAddIPAddress.Run();
  108. // Contact user agent
  109. this.apiAddUserAgent.Run();
  110. // Account
  111. this.apiCreateAccount.Run();
  112. this.apiGetAndUpdateAccount.Run();
  113. this.apiGetAndBulkUpdateAccounts.Run();
  114. // Account with account status
  115. this.apiAddAccountStatusToAccount.Run();
  116. // Account with contact
  117. this.apiAddContactToAccount.Run();
  118. // Contact group
  119. this.apiCreateContactGroup.Run();
  120. this.apiGetAndUpdateContactGroup.Run();
  121. this.apiGetAndBulkUpdateContactGroups.Run();
  122. // Contact in group
  123. this.apiAddContactToGroup.Run();
  124. // Account in group
  125. this.apiAddAccountToGroup.Run();
  126. // Activity
  127. this.apiCreateActivity.Run();
  128. this.apiGetAndUpdateActivity.Run();
  129. this.apiGetAndBulkUpdateActivities.Run();
  130. }
  131. /// <summary>
  132. /// Runs all cleanup examples.
  133. /// </summary>
  134. public override void CleanUpAll()
  135. {
  136. base.CleanUpAll();
  137. // Activity
  138. this.apiDeleteActivity.Run();
  139. // Contact group
  140. this.apiRemoveContactFromGroup.Run();
  141. this.apiRemoveAccountFromGroup.Run();
  142. this.apiDeleteContactGroup.Run();
  143. // Account
  144. this.apiRemoveContactFromAccount.Run();
  145. this.apiRemoveAccountStatusFromAccount.Run();
  146. this.apiDeleteAccount.Run();
  147. // Contact
  148. this.apiRemoveIPAddress.Run();
  149. this.apiRemoveUserAgent.Run();
  150. this.apiRemoveMembership.Run();
  151. this.apiRemoveContactStatusFromContact.Run();
  152. this.apiDeleteContact.Run();
  153. // Account status
  154. this.apiDeleteAccountStatus.Run();
  155. // Contact status
  156. this.apiDeleteContactStatus.Run();
  157. // Contact role
  158. this.apiDeleteContactRole.Run();
  159. }
  160. #endregion
  161. #region "API examples - Contact role"
  162. /// <summary>
  163. /// Creates contact role. Called when the "Create role" button is pressed.
  164. /// </summary>
  165. private bool CreateContactRole()
  166. {
  167. // Create new contact role object
  168. ContactRoleInfo newRole = new ContactRoleInfo()
  169. {
  170. ContactRoleDisplayName = "My new role",
  171. ContactRoleName = "MyNewRole",
  172. ContactRoleSiteID = CMSContext.CurrentSiteID
  173. };
  174. // Save the contact role
  175. ContactRoleInfoProvider.SetContactRoleInfo(newRole);
  176. return true;
  177. }
  178. /// <summary>
  179. /// Gets and updates contact role. Called when the "Get and update role" button is pressed.
  180. /// Expects the CreateContactRole method to be run first.
  181. /// </summary>
  182. private bool GetAndUpdateContactRole()
  183. {
  184. // Get the contact role
  185. ContactRoleInfo updateRole = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", CMSContext.CurrentSiteName);
  186. if (updateRole != null)
  187. {
  188. // Update a property
  189. updateRole.ContactRoleDisplayName = updateRole.ContactRoleDisplayName.ToLower();
  190. // Save the changes
  191. ContactRoleInfoProvider.SetContactRoleInfo(updateRole);
  192. return true;
  193. }
  194. return false;
  195. }
  196. /// <summary>
  197. /// Gets and bulk updates contact roles. Called when the "Get and bulk update roles" button is pressed.
  198. /// Expects the CreateContactRole method to be run first.
  199. /// </summary>
  200. private bool GetAndBulkUpdateContactRoles()
  201. {
  202. // Get the contact roles dataset
  203. string where = "ContactRoleName LIKE N'MyNewRole%'";
  204. InfoDataSet<ContactRoleInfo> roles = ContactRoleInfoProvider.GetContactRoles(where, null);
  205. if (!DataHelper.DataSourceIsEmpty(roles))
  206. {
  207. foreach (ContactRoleInfo role in roles)
  208. {
  209. // Update the properties
  210. role.ContactRoleDisplayName = role.ContactRoleDisplayName.ToUpper();
  211. // Save the changes
  212. ContactRoleInfoProvider.SetContactRoleInfo(role);
  213. }
  214. return true;
  215. }
  216. return false;
  217. }
  218. /// <summary>
  219. /// Deletes contact role. Called when the "Delete role" button is pressed.
  220. /// Expects the CreateContactRole method to be run first.
  221. /// </summary>
  222. private bool DeleteContactRole()
  223. {
  224. // Get the contact role
  225. ContactRoleInfo deleteRole = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", CMSContext.CurrentSiteName);
  226. if (deleteRole != null)
  227. {
  228. // Delete the contact role
  229. ContactRoleInfoProvider.DeleteContactRoleInfo(deleteRole);
  230. return true;
  231. }
  232. return false;
  233. }
  234. #endregion
  235. #region "API examples - Contact status"
  236. /// <summary>
  237. /// Creates contact status. Called when the "Create status" button is pressed.
  238. /// </summary>
  239. private bool CreateContactStatus()
  240. {
  241. // Create new contact status object
  242. ContactStatusInfo newStatus = new ContactStatusInfo()
  243. {
  244. ContactStatusDisplayName = "My new status",
  245. ContactStatusName = "MyNewStatus",
  246. ContactStatusSiteID = CMSContext.CurrentSiteID
  247. };
  248. // Save the contact status
  249. ContactStatusInfoProvider.SetContactStatusInfo(newStatus);
  250. return true;
  251. }
  252. /// <summary>
  253. /// Gets and updates contact status. Called when the "Get and update status" button is pressed.
  254. /// Expects the CreateContactStatus method to be run first.
  255. /// </summary>
  256. private bool GetAndUpdateContactStatus()
  257. {
  258. // Get the contact status
  259. ContactStatusInfo updateStatus = ContactStatusInfoProvider.GetContactStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  260. if (updateStatus != null)
  261. {
  262. // Update a property
  263. updateStatus.ContactStatusDisplayName = updateStatus.ContactStatusDisplayName.ToLower();
  264. // Save the changes
  265. ContactStatusInfoProvider.SetContactStatusInfo(updateStatus);
  266. return true;
  267. }
  268. return false;
  269. }
  270. /// <summary>
  271. /// Gets and bulk updates contact statuses. Called when the "Get and bulk update statuses" button is pressed.
  272. /// Expects the CreateContactStatus method to be run first.
  273. /// </summary>
  274. private bool GetAndBulkUpdateContactStatuses()
  275. {
  276. // Get the contact statuses dataset
  277. string where = "ContactStatusName LIKE N'MyNewStatus%'";
  278. InfoDataSet<ContactStatusInfo> statuses = ContactStatusInfoProvider.GetContactStatuses(where, null);
  279. if (!DataHelper.DataSourceIsEmpty(statuses))
  280. {
  281. foreach (ContactStatusInfo contactStatus in statuses)
  282. {
  283. // Update a property
  284. contactStatus.ContactStatusDisplayName = contactStatus.ContactStatusDisplayName.ToUpper();
  285. // Save the changes
  286. ContactStatusInfoProvider.SetContactStatusInfo(contactStatus);
  287. }
  288. return true;
  289. }
  290. return false;
  291. }
  292. /// <summary>
  293. /// Deletes contact status. Called when the "Delete status" button is pressed.
  294. /// Expects the CreateContactStatus method to be run first.
  295. /// </summary>
  296. private bool DeleteContactStatus()
  297. {
  298. // Get the contact status
  299. ContactStatusInfo deleteStatus = ContactStatusInfoProvider.GetContactStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  300. if (deleteStatus != null)
  301. {
  302. // Delete the contact status
  303. ContactStatusInfoProvider.DeleteContactStatusInfo(deleteStatus);
  304. return true;
  305. }
  306. return false;
  307. }
  308. #endregion
  309. #region "API examples - Account status"
  310. /// <summary>
  311. /// Creates account status. Called when the "Create status" button is pressed.
  312. /// </summary>
  313. private bool CreateAccountStatus()
  314. {
  315. // Create new account status object
  316. AccountStatusInfo newStatus = new AccountStatusInfo()
  317. {
  318. AccountStatusDisplayName = "My new status",
  319. AccountStatusName = "MyNewStatus",
  320. AccountStatusSiteID = CMSContext.CurrentSiteID
  321. };
  322. // Save the account status
  323. AccountStatusInfoProvider.SetAccountStatusInfo(newStatus);
  324. return true;
  325. }
  326. /// <summary>
  327. /// Gets and updates account status. Called when the "Get and update status" button is pressed.
  328. /// Expects the CreateAccountStatus method to be run first.
  329. /// </summary>
  330. private bool GetAndUpdateAccountStatus()
  331. {
  332. // Get the account status
  333. AccountStatusInfo updateStatus = AccountStatusInfoProvider.GetAccountStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  334. if (updateStatus != null)
  335. {
  336. // Update a property
  337. updateStatus.AccountStatusDisplayName = updateStatus.AccountStatusDisplayName.ToLower();
  338. // Save the changes
  339. AccountStatusInfoProvider.SetAccountStatusInfo(updateStatus);
  340. return true;
  341. }
  342. return false;
  343. }
  344. /// <summary>
  345. /// Gets and bulk updates account statuses. Called when the "Get and bulk update statuses" button is pressed.
  346. /// Expects the CreateAccountStatus method to be run first.
  347. /// </summary>
  348. private bool GetAndBulkUpdateAccountStatuses()
  349. {
  350. // Get the account status dataset
  351. string where = "AccountStatusName LIKE N'MyNewStatus%'";
  352. InfoDataSet<AccountStatusInfo> statuses = AccountStatusInfoProvider.GetAccountStatuses(where, null);
  353. if (!DataHelper.DataSourceIsEmpty(statuses))
  354. {
  355. foreach (AccountStatusInfo accountStatus in statuses)
  356. {
  357. // Update a property
  358. accountStatus.AccountStatusDisplayName = accountStatus.AccountStatusDisplayName.ToUpper();
  359. // Save the changes
  360. AccountStatusInfoProvider.SetAccountStatusInfo(accountStatus);
  361. }
  362. return true;
  363. }
  364. return false;
  365. }
  366. /// <summary>
  367. /// Deletes account status. Called when the "Delete status" button is pressed.
  368. /// Expects the CreateAccountStatus method to be run first.
  369. /// </summary>
  370. private bool DeleteAccountStatus()
  371. {
  372. // Get the account status
  373. AccountStatusInfo deleteStatus = AccountStatusInfoProvider.GetAccountStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  374. if (deleteStatus != null)
  375. {
  376. // Delete the account status
  377. AccountStatusInfoProvider.DeleteAccountStatusInfo(deleteStatus);
  378. return true;
  379. }
  380. return false;
  381. }
  382. #endregion
  383. #region "API examples - Contact"
  384. /// <summary>
  385. /// Creates contact. Called when the "Create contact" button is pressed.
  386. /// </summary>
  387. private bool CreateContact()
  388. {
  389. // Create new contact object
  390. ContactInfo newContact = new ContactInfo()
  391. {
  392. ContactLastName = "My New Contact",
  393. ContactFirstName = "My New Firstname",
  394. ContactSiteID = CMSContext.CurrentSiteID,
  395. ContactIsAnonymous = true
  396. };
  397. // Save the contact
  398. ContactInfoProvider.SetContactInfo(newContact);
  399. return true;
  400. }
  401. /// <summary>
  402. /// Gets and updates contact. Called when the "Get and update contact" button is pressed.
  403. /// Expects the CreateContact method to be run first.
  404. /// </summary>
  405. private bool GetAndUpdateContact()
  406. {
  407. // Get dataset of contacts
  408. string where = "ContactLastName LIKE N'My New Contact%'";
  409. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  410. if (!DataHelper.DataSourceIsEmpty(contacts))
  411. {
  412. // Get the contact from dataset
  413. ContactInfo contact = contacts.First<ContactInfo>();
  414. // Update a property
  415. contact.ContactLastName = contact.ContactLastName.ToLower();
  416. // Save the changes
  417. ContactInfoProvider.SetContactInfo(contact);
  418. return true;
  419. }
  420. return false;
  421. }
  422. /// <summary>
  423. /// Gets and bulk updates contacts. Called when the "Get and bulk update contacts" button is pressed.
  424. /// Expects the CreateContact method to be run first.
  425. /// </summary>
  426. private bool GetAndBulkUpdateContacts()
  427. {
  428. // Get dataset of contacts
  429. string where = "ContactLastName LIKE N'My New Contact%'";
  430. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null);
  431. if (!DataHelper.DataSourceIsEmpty(contacts))
  432. {
  433. foreach (ContactInfo contact in contacts)
  434. {
  435. // Update a property of each contact
  436. contact.ContactLastName = contact.ContactLastName.ToUpper();
  437. // And save them
  438. ContactInfoProvider.SetContactInfo(contact);
  439. }
  440. return true;
  441. }
  442. return false;
  443. }
  444. /// <summary>
  445. /// Adds contact status to contact. Called when the "Add contact status to contact" button is pressed.
  446. /// Expects the CreateContact and CreateContactStatus methods to be run first.
  447. /// </summary>
  448. private bool AddContactStatusToContact()
  449. {
  450. // Get dataset of contacts
  451. string where = "ContactLastName LIKE N'My New Contact%'";
  452. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  453. // Get the contact status
  454. ContactStatusInfo contactStatus = ContactStatusInfoProvider.GetContactStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  455. if (!DataHelper.DataSourceIsEmpty(contacts) && (contactStatus != null))
  456. {
  457. // Get the contact from dataset
  458. ContactInfo contact = contacts.First<ContactInfo>();
  459. // If relationship doesn't already exist
  460. if (contact.ContactStatusID != contactStatus.ContactStatusID)
  461. {
  462. // Add contact status to contact
  463. contact.ContactStatusID = contactStatus.ContactStatusID;
  464. // Save the changes
  465. ContactInfoProvider.SetContactInfo(contact);
  466. return true;
  467. }
  468. }
  469. return false;
  470. }
  471. /// <summary>
  472. /// Removes contact status from contact. Called when the "Remove status from contact" button is pressed.
  473. /// Expects the CreateContact, CreateContactStatus and AddContactStatusToContact methods to be run first.
  474. /// </summary>
  475. private bool RemoveContactStatusFromContact()
  476. {
  477. // Get dataset of contacts
  478. string where = "ContactLastName LIKE N'My New Contact%'";
  479. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  480. // Get the contact status
  481. ContactStatusInfo contactStatus = ContactStatusInfoProvider.GetContactStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  482. if (!DataHelper.DataSourceIsEmpty(contacts) && (contactStatus != null))
  483. {
  484. // Get the contact from dataset
  485. ContactInfo contact = contacts.First<ContactInfo>();
  486. // If relationship exists
  487. if (contact.ContactStatusID == contactStatus.ContactStatusID)
  488. {
  489. // Remove the status
  490. contact.ContactStatusID = 0;
  491. // Save the changes
  492. ContactInfoProvider.SetContactInfo(contact);
  493. return true;
  494. }
  495. }
  496. return false;
  497. }
  498. /// <summary>
  499. /// Adds current user to contact. Called when the "Add membership to contact" button is pressed.
  500. /// Expects the CreateContact method to be run first.
  501. /// </summary>
  502. private bool AddMembership()
  503. {
  504. // Get dataset of contacts
  505. string where = "ContactLastName LIKE N'My New Contact%'";
  506. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  507. if (!DataHelper.DataSourceIsEmpty(contacts))
  508. {
  509. // Get the contact from dataset
  510. ContactInfo contact = contacts.First<ContactInfo>();
  511. // Set relationship to user
  512. CMS.OnlineMarketing.MembershipInfoProvider.SetRelationship(
  513. CMSContext.CurrentUser.UserID,
  514. MemberTypeEnum.CmsUser,
  515. contact.ContactID,
  516. contact.ContactID,
  517. false);
  518. return true;
  519. }
  520. return false;
  521. }
  522. /// <summary>
  523. /// Removes current user from contact. Called when the "Remove membership from contact" button is pressed.
  524. /// Expects the CreateContact and AddMembership methods to be run first.
  525. /// </summary>
  526. private bool RemoveMembership()
  527. {
  528. // Get dataset of contacts
  529. string where = "ContactLastName LIKE N'My New Contact%'";
  530. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  531. if (!DataHelper.DataSourceIsEmpty(contacts))
  532. {
  533. // Get the contact from dataset
  534. ContactInfo contact = contacts.First<ContactInfo>();
  535. // Get the membership
  536. CMS.OnlineMarketing.MembershipInfo membership = CMS.OnlineMarketing.MembershipInfoProvider.GetMembershipInfo(contact.ContactID, contact.ContactID, CMSContext.CurrentUser.UserID, MemberTypeEnum.CmsUser);
  537. // Delete the membership
  538. CMS.OnlineMarketing.MembershipInfoProvider.DeleteRelationship(membership.MembershipID);
  539. return (membership != null);
  540. }
  541. return false;
  542. }
  543. /// <summary>
  544. /// Adds IP address to contact. Called when the "Add IP to contact" button is pressed.
  545. /// Expects the CreateContact method to be run first.
  546. /// </summary>
  547. private bool AddIPAddress()
  548. {
  549. // Get dataset of contacts
  550. string where = "ContactLastName LIKE N'My New Contact%'";
  551. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  552. if (!DataHelper.DataSourceIsEmpty(contacts))
  553. {
  554. // Get the contact from dataset
  555. ContactInfo contact = contacts.First<ContactInfo>();
  556. // Create new IP address
  557. IPInfo newIP = new IPInfo()
  558. {
  559. IPAddress = "127.0.0.1",
  560. IPOriginalContactID = contact.ContactID,
  561. IPActiveContactID = contact.ContactID
  562. };
  563. // Save the IP info
  564. IPInfoProvider.SetIPInfo(newIP);
  565. return true;
  566. }
  567. return false;
  568. }
  569. /// <summary>
  570. /// Removes IP address from contact. Called when the "Remove IP from contact" button is pressed.
  571. /// Expects the CreateContact and AddIPAddress methods to be run first.
  572. /// </summary>
  573. private bool RemoveIPAddress()
  574. {
  575. // Get dataset of contacts
  576. string where = "ContactLastName LIKE N'My New Contact%'";
  577. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  578. if (!DataHelper.DataSourceIsEmpty(contacts))
  579. {
  580. // Get the contact from dataset
  581. ContactInfo contact = contacts.First<ContactInfo>();
  582. // Get contact's IP
  583. where = String.Format("IPOriginalContactID = '{0}' AND IPAddress = '{1}'", contact.ContactID, "127.0.0.1");
  584. InfoDataSet<IPInfo> deleteIPs = IPInfoProvider.GetIps(where, null, 1, "IPID");
  585. if (!DataHelper.DataSourceIsEmpty(deleteIPs))
  586. {
  587. // Delete IP
  588. IPInfoProvider.DeleteIPInfo(deleteIPs.First<IPInfo>());
  589. return true;
  590. }
  591. }
  592. return false;
  593. }
  594. /// <summary>
  595. /// Adds user agent to contact. Called when the "Add user agent to contact" button is pressed.
  596. /// Expects the CreateContact method to be run first.
  597. /// </summary>
  598. private bool AddUserAgent()
  599. {
  600. // Get dataset of contacts
  601. string where = "ContactLastName LIKE N'My New Contact%'";
  602. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  603. if (!DataHelper.DataSourceIsEmpty(contacts))
  604. {
  605. // Get the contact from dataset
  606. ContactInfo contact = contacts.First<ContactInfo>();
  607. // Create new agent info
  608. UserAgentInfo agentInfo = new UserAgentInfo()
  609. {
  610. UserAgentActiveContactID = contact.ContactID,
  611. UserAgentOriginalContactID = contact.ContactID,
  612. UserAgentString = "My User Agent"
  613. };
  614. // Save the agent info
  615. UserAgentInfoProvider.SetUserAgentInfo(agentInfo);
  616. return true;
  617. }
  618. return false;
  619. }
  620. /// <summary>
  621. /// Removes user agent from contact. Called when the "Remove user agent from contact" button is pressed.
  622. /// Expects the CreateContact and AddUserAgent methods to be run first.
  623. /// </summary>
  624. private bool RemoveUserAgent()
  625. {
  626. // Get dataset of contacts
  627. string where = "ContactLastName LIKE N'My New Contact%'";
  628. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  629. if (!DataHelper.DataSourceIsEmpty(contacts))
  630. {
  631. // Get the contact from dataset
  632. ContactInfo contact = contacts.First<ContactInfo>();
  633. // Get the user agent info
  634. where = String.Format("UserAgentOriginalContactID = '{0}' AND UserAgentString = '{1}'", contact.ContactID, "My User Agent");
  635. InfoDataSet<UserAgentInfo> deleteAgents = UserAgentInfoProvider.GetUserAgents(where, null, 1, null);
  636. if (!DataHelper.DataSourceIsEmpty(deleteAgents))
  637. {
  638. // Delete the user agent info
  639. UserAgentInfoProvider.DeleteUserAgentInfo(deleteAgents.First<UserAgentInfo>());
  640. return true;
  641. }
  642. }
  643. return false;
  644. }
  645. /// <summary>
  646. /// Deletes contact. Called when the "Delete contact" button is pressed.
  647. /// Expects the CreateContact method to be run first.
  648. /// </summary>
  649. private bool DeleteContact()
  650. {
  651. // Get dataset of contacts
  652. string where = "ContactLastName LIKE N'My New Contact%'";
  653. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  654. if (!DataHelper.DataSourceIsEmpty(contacts))
  655. {
  656. // Get the contact from dataset
  657. ContactInfo contact = contacts.First<ContactInfo>();
  658. // Delete the contact
  659. ContactInfoProvider.DeleteContactInfo(contact);
  660. return true;
  661. }
  662. return false;
  663. }
  664. #endregion
  665. #region "API examples - Account"
  666. /// <summary>
  667. /// Creates account. Called when the "Create account" button is pressed.
  668. /// </summary>
  669. private bool CreateAccount()
  670. {
  671. // Create new account object
  672. AccountInfo newAccount = new AccountInfo()
  673. {
  674. AccountName = "My New Account",
  675. AccountSiteID = CMSContext.CurrentSiteID
  676. };
  677. // Save the account
  678. AccountInfoProvider.SetAccountInfo(newAccount);
  679. return true;
  680. }
  681. /// <summary>
  682. /// Gets and updates account. Called when the "Get and update account" button is pressed.
  683. /// Expects the CreateAccount method to be run first.
  684. /// </summary>
  685. private bool GetAndUpdateAccount()
  686. {
  687. // Get the account
  688. AccountInfo updateAccount = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  689. if (updateAccount != null)
  690. {
  691. // Update a property
  692. updateAccount.AccountName = updateAccount.AccountName.ToLower();
  693. // And save it
  694. AccountInfoProvider.SetAccountInfo(updateAccount);
  695. return true;
  696. }
  697. return false;
  698. }
  699. /// <summary>
  700. /// Gets and bulk updates accounts. Called when the "Get and bulk update accounts" button is pressed.
  701. /// Expects the CreateAccount method to be run first.
  702. /// </summary>
  703. private bool GetAndBulkUpdateAccounts()
  704. {
  705. // Get dataset of accounts
  706. string where = "AccountName LIKE N'My New Account%'";
  707. InfoDataSet<AccountInfo> accounts = AccountInfoProvider.GetAccounts(where, null);
  708. if (!DataHelper.DataSourceIsEmpty(accounts))
  709. {
  710. foreach (AccountInfo account in accounts)
  711. {
  712. // Update each one's property
  713. account.AccountName = account.AccountName.ToUpper();
  714. // And save it
  715. AccountInfoProvider.SetAccountInfo(account);
  716. }
  717. return true;
  718. }
  719. return false;
  720. }
  721. /// <summary>
  722. /// Gets and bulk updates accounts. Called when the "Get and bulk update accounts" button is pressed.
  723. /// Expects the CreateAccount method to be run first.
  724. /// </summary>
  725. private bool AddAccountStatusToAccount()
  726. {
  727. // Get the account
  728. AccountInfo account = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  729. // Get the account status
  730. AccountStatusInfo accountStatus = AccountStatusInfoProvider.GetAccountStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  731. if ((account != null) && (accountStatus != null))
  732. {
  733. // Check that account doesn't have this status
  734. if (account.AccountStatusID != accountStatus.AccountStatusID)
  735. {
  736. // Set new status
  737. account.AccountStatusID = accountStatus.AccountStatusID;
  738. // Save changes to the object
  739. AccountInfoProvider.SetAccountInfo(account);
  740. return true;
  741. }
  742. }
  743. return false;
  744. }
  745. /// <summary>
  746. /// Removes account status from account. Called when the "Remove status from account" button is pressed.
  747. /// Expects the CreateAccount, CreateAccountStatus and AddAccountStatusToAccount methods to be run first.
  748. /// </summary>
  749. private bool RemoveAccountStatusFromAccount()
  750. {
  751. // Get the account
  752. AccountInfo account = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  753. // Get the account status
  754. AccountStatusInfo accountStatus = AccountStatusInfoProvider.GetAccountStatusInfo("MyNewStatus", CMSContext.CurrentSiteName);
  755. if ((account != null) && (accountStatus != null))
  756. {
  757. // Check if account has this status set
  758. if (account.AccountStatusID == accountStatus.AccountStatusID)
  759. {
  760. // Remove the status from account
  761. account.AccountStatusID = 0;
  762. // Save the object
  763. AccountInfoProvider.SetAccountInfo(account);
  764. return true;
  765. }
  766. }
  767. return false;
  768. }
  769. /// <summary>
  770. /// Adds contact under account.
  771. /// </summary>
  772. private bool AddContactToAccount()
  773. {
  774. // Get dataset of contacts
  775. string where = "ContactLastName LIKE N'My New Contact%'";
  776. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  777. // Get the account
  778. AccountInfo account = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  779. // Get the role
  780. ContactRoleInfo role = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", CMSContext.CurrentSiteName);
  781. if (!DataHelper.DataSourceIsEmpty(contacts) && (account != null) && (role != null))
  782. {
  783. // Get the contact from dataset
  784. ContactInfo contact = contacts.First<ContactInfo>();
  785. // Create new account - contact relationship
  786. AccountContactInfo accountContact = new AccountContactInfo()
  787. {
  788. AccountID = account.AccountID,
  789. ContactID = contact.ContactID,
  790. ContactRoleID = role.ContactRoleID
  791. };
  792. // And save it
  793. AccountContactInfoProvider.SetAccountContactInfo(accountContact);
  794. return true;
  795. }
  796. return false;
  797. }
  798. /// <summary>
  799. /// Removes contact from account.
  800. /// </summary>
  801. private bool RemoveContactFromAccount()
  802. {
  803. // Get dataset of contacts
  804. string where = "ContactLastName LIKE N'My New Contact%'";
  805. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  806. // Get the account
  807. AccountInfo account = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  808. if (!DataHelper.DataSourceIsEmpty(contacts) && (account != null))
  809. {
  810. // Get the contact from dataset
  811. ContactInfo contact = contacts.First<ContactInfo>();
  812. // Find account - contact relationship
  813. AccountContactInfo accountContact = AccountContactInfoProvider.GetAccountContactInfo(account.AccountID, contact.ContactID);
  814. if (accountContact != null)
  815. {
  816. // Delete the object
  817. AccountContactInfoProvider.DeleteAccountContactInfo(accountContact);
  818. return true;
  819. }
  820. }
  821. return false;
  822. }
  823. /// <summary>
  824. /// Deletes account. Called when the "Delete account" button is pressed.
  825. /// Expects the CreateAccount method to be run first.
  826. /// </summary>
  827. private bool DeleteAccount()
  828. {
  829. // Get the account
  830. AccountInfo deleteAccount = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  831. if (deleteAccount != null)
  832. {
  833. // Delete the account
  834. AccountInfoProvider.DeleteAccountInfo(deleteAccount);
  835. return true;
  836. }
  837. return false;
  838. }
  839. #endregion
  840. #region "API examples - Contact group"
  841. /// <summary>
  842. /// Creates contact group. Called when the "Create group" button is pressed.
  843. /// </summary>
  844. private bool CreateContactGroup()
  845. {
  846. // Create new contact group object
  847. ContactGroupInfo newGroup = new ContactGroupInfo()
  848. {
  849. ContactGroupDisplayName = "My new group",
  850. ContactGroupName = "MyNewGroup",
  851. ContactGroupSiteID = CMSContext.CurrentSiteID,
  852. ContactGroupDynamicCondition = "{%Contact.ContactLastName.Contains(\"My new\")%}"
  853. };
  854. // Save the contact group to database
  855. ContactGroupInfoProvider.SetContactGroupInfo(newGroup);
  856. return true;
  857. }
  858. /// <summary>
  859. /// Gets and updates contact group. Called when the "Get and update group" button is pressed.
  860. /// Expects the CreateContactGroup method to be run first.
  861. /// </summary>
  862. private bool GetAndUpdateContactGroup()
  863. {
  864. // Get the contact group
  865. ContactGroupInfo updateGroup = ContactGroupInfoProvider.GetContactGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
  866. if (updateGroup != null)
  867. {
  868. // Update contact group's properties
  869. updateGroup.ContactGroupDisplayName = updateGroup.ContactGroupDisplayName.ToLower();
  870. // Save the contact group
  871. ContactGroupInfoProvider.SetContactGroupInfo(updateGroup);
  872. return true;
  873. }
  874. return false;
  875. }
  876. /// <summary>
  877. /// Gets and bulk updates contact groups. Called when the "Get and bulk update groups" button is pressed.
  878. /// Expects the CreateContactGroup method to be run first.
  879. /// </summary>
  880. private bool GetAndBulkUpdateContactGroups()
  881. {
  882. // Get the contact groups
  883. string where = "ContactGroupName LIKE N'MyNewGroup%'";
  884. InfoDataSet<ContactGroupInfo> groups = ContactGroupInfoProvider.GetContactGroups(where, null);
  885. if (!DataHelper.DataSourceIsEmpty(groups))
  886. {
  887. foreach (ContactGroupInfo group in groups)
  888. {
  889. // Update a property
  890. group.ContactGroupDisplayName = group.ContactGroupDisplayName.ToUpper();
  891. // Save the contact group
  892. ContactGroupInfoProvider.SetContactGroupInfo(group);
  893. }
  894. return true;
  895. }
  896. return false;
  897. }
  898. /// <summary>
  899. /// Adds contact to group. Called when the "Add contact to group" button is pressed.
  900. /// Exepects the CreateContact and CreateContactGroup methods to be run first.
  901. /// </summary>
  902. private bool AddContactToGroup()
  903. {
  904. // Get dataset of contacts
  905. string where = "ContactLastName LIKE N'My New Contact%'";
  906. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  907. // Get the contact group
  908. ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
  909. if (!DataHelper.DataSourceIsEmpty(contacts) && (group != null))
  910. {
  911. // Get the contact from dataset
  912. ContactInfo contact = contacts.First<ContactInfo>();
  913. // Create the contact - contactgroup relationship
  914. ContactGroupMemberInfo newContactGroupMember = new ContactGroupMemberInfo()
  915. {
  916. ContactGroupMemberContactGroupID = group.ContactGroupID,
  917. ContactGroupMemberType = ContactGroupMemberTypeEnum.Contact,
  918. ContactGroupMemberRelatedID = contact.ContactID,
  919. ContactGroupMemberFromManual = true
  920. };
  921. // Save the contact group
  922. ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(newContactGroupMember);
  923. return true;
  924. }
  925. return false;
  926. }
  927. /// <summary>
  928. /// Removes contact from group. Called when the "Remove contact from group" button is pressed.
  929. /// Expects the CreateContact, CreateContactGroup and AddContactToGroup methods to be run first.
  930. /// </summary>
  931. private bool RemoveContactFromGroup()
  932. {
  933. // Get dataset of contacts
  934. string where = "ContactLastName LIKE N'My New Contact%'";
  935. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  936. // Get the contact group
  937. ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
  938. if (!DataHelper.DataSourceIsEmpty(contacts) && (group != null))
  939. {
  940. // Get the contact from dataset
  941. ContactInfo contact = contacts.First<ContactInfo>();
  942. // Get the contact - contactgroup relationship
  943. ContactGroupMemberInfo deleteContactGroupMember = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(group.ContactGroupID, contact.ContactID, ContactGroupMemberTypeEnum.Contact);
  944. if (deleteContactGroupMember != null)
  945. {
  946. // Delete the info
  947. ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(deleteContactGroupMember);
  948. return true;
  949. }
  950. }
  951. return false;
  952. }
  953. /// <summary>
  954. /// Adds account to group. Called when the "Add account to group" button is pressed.
  955. /// Expects the CreateAccount and CreateGroup methods to be run first.
  956. /// </summary>
  957. private bool AddAccountToGroup()
  958. {
  959. // Get the account
  960. AccountInfo account = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  961. // Get the contact group
  962. ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
  963. if ((account != null) && (group != null))
  964. {
  965. // Create new account - contact group relationship
  966. ContactGroupMemberInfo newContactGroupMember = new ContactGroupMemberInfo()
  967. {
  968. ContactGroupMemberContactGroupID = group.ContactGroupID,
  969. ContactGroupMemberType = ContactGroupMemberTypeEnum.Account,
  970. ContactGroupMemberRelatedID = account.AccountID
  971. };
  972. // Save the object
  973. ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(newContactGroupMember);
  974. return true;
  975. }
  976. return false;
  977. }
  978. /// <summary>
  979. /// Removes account from group. Called when the "Remove account from group" button is pressed.
  980. /// Expects the CreateAccount, CreateGroup and AddContactToGroup methods to be run first.
  981. /// </summary>
  982. private bool RemoveAccountFromGroup()
  983. {
  984. // Get the account
  985. AccountInfo account = AccountInfoProvider.GetAccountInfo("My New Account", CMSContext.CurrentSiteName);
  986. // Get the contact group
  987. ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
  988. if ((account != null) && (group != null))
  989. {
  990. // Get the account - contactgroup relationship
  991. ContactGroupMemberInfo deleteContactGroupMember = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(group.ContactGroupID, account.AccountID, ContactGroupMemberTypeEnum.Account);
  992. if (deleteContactGroupMember != null)
  993. {
  994. // Delete the info
  995. ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(deleteContactGroupMember);
  996. return true;
  997. }
  998. }
  999. return false;
  1000. }
  1001. /// <summary>
  1002. /// Deletes contact group. Called when the "Delete group" button is pressed.
  1003. /// Expects the CreateContactGroup method to be run first.
  1004. /// </summary>
  1005. private bool DeleteContactGroup()
  1006. {
  1007. // Get the contact group
  1008. ContactGroupInfo deleteGroup = ContactGroupInfoProvider.GetContactGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);
  1009. if (deleteGroup != null)
  1010. {
  1011. // Delete the contact group
  1012. ContactGroupInfoProvider.DeleteContactGroupInfo(deleteGroup);
  1013. return true;
  1014. }
  1015. return false;
  1016. }
  1017. #endregion
  1018. #region "API examples - Activity"
  1019. /// <summary>
  1020. /// Creates activity. Called when the "Create activity" button is pressed.
  1021. /// </summary>
  1022. private bool CreateActivity()
  1023. {
  1024. // Get dataset of contacts
  1025. string where = "ContactLastName LIKE N'My New Contact%'";
  1026. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  1027. if (!DataHelper.DataSourceIsEmpty(contacts))
  1028. {
  1029. // Get the contact from dataset
  1030. ContactInfo contact = contacts.First<ContactInfo>();
  1031. // Get an activity type
  1032. ActivityTypeInfo activityType = ActivityTypeInfoProvider.GetActivityTypes(null, null, 1, null).First<ActivityTypeInfo>();
  1033. // Create new activity object
  1034. ActivityInfo newActivity = new ActivityInfo()
  1035. {
  1036. ActivityType = activityType.ActivityTypeName,
  1037. ActivityTitle = "My new activity",
  1038. ActivitySiteID = CMSContext.CurrentSiteID,
  1039. ActivityOriginalContactID = contact.ContactID,
  1040. ActivityActiveContactID = contact.ContactID
  1041. };
  1042. // Save the activity
  1043. ActivityInfoProvider.SetActivityInfo(newActivity);
  1044. return true;
  1045. }
  1046. return false;
  1047. }
  1048. /// <summary>
  1049. /// Gets and updates activity. Called when the "Get and update activity" button is pressed.
  1050. /// Expects the CreateActivity method to be run first.
  1051. /// </summary>
  1052. private bool GetAndUpdateActivity()
  1053. {
  1054. // Get dataset of contacts
  1055. string where = "ContactLastName LIKE N'My New Contact%'";
  1056. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  1057. if (!DataHelper.DataSourceIsEmpty(contacts))
  1058. {
  1059. // Get the contact from dataset
  1060. ContactInfo contact = contacts.First<ContactInfo>();
  1061. // Get all activities associated with user
  1062. where = String.Format("ActivityActiveContactID = '{0}'", contact.ContactID);
  1063. InfoDataSet<ActivityInfo> updateActivities = ActivityInfoProvider.GetActivities(where, null);
  1064. if (!DataHelper.DataSourceIsEmpty(updateActivities))
  1065. {
  1066. // Get just the first activity
  1067. ActivityInfo activity = updateActivities.First<ActivityInfo>();
  1068. // Update the activity
  1069. activity.ActivityTitle = activity.ActivityTitle.ToLower();
  1070. // Save the activity
  1071. ActivityInfoProvider.SetActivityInfo(activity);
  1072. return true;
  1073. }
  1074. }
  1075. return false;
  1076. }
  1077. /// <summary>
  1078. /// Gets and bulk updates activities. Called when the "Get and bulk update activities" button is pressed.
  1079. /// Expects the CreateActivity method to be run first.
  1080. /// </summary>
  1081. private bool GetAndBulkUpdateActivities()
  1082. {
  1083. // Get dataset of contacts
  1084. string where = "ContactLastName LIKE N'My New Contact%'";
  1085. InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);
  1086. if (!DataHelper.DataSourceIsEmpty(contacts))
  1087. {
  1088. // Get the contact from dataset
  1089. ContactInfo contact = contacts.First<ContactInfo>();
  1090. // Get all activities associated with contact
  1091. where = String.Format("ActivityActiveContactID = '{0}'", contact.ContactID);
  1092. InfoDataSet<ActivityInfo> updateActivities = ActivityInfoProvider.GetActivities(where, null);
  1093. if (!DataHelper.DataSourceIsEmpty(updateActivities))
  1094. {
  1095. foreach (ActivityInfo activity in updateActivities)
  1096. {
  1097. // Update activit