void ucSelectCustomer_Changed(object sender, EventArgs e) { // Check permissions if (ContactHelper.AuthorizedModifyContact(ci.ContactSiteID, true)) { // Load value form dynamic control string values = null; if (ucSelectCustomer != null) { values = ValidationHelper.GetString(ucSelectCustomer.GetValue("OnlineMarketingValue"), null); } if (!String.IsNullOrEmpty(values)) { // Store users one by one string[] customerIds = values.Split(';'); foreach (string customerId in customerIds) { // Check if user ID is valid int customerIdInt = ValidationHelper.GetInteger(customerId, 0); if (customerIdInt <= 0) { continue; } // Add new relation int parentId = (ci.ContactMergedWithContactID == 0) ? ci.ContactID : ci.ContactMergedWithContactID; MembershipInfoProvider.SetRelationship(customerIdInt, MemberTypeEnum.EcommerceCustomer, ci.ContactID, parentId, true); ci = ContactInfoProvider.GetContactInfo(contactId); } // When contact was merged then refresh complete page if ((ci != null) && (ci.ContactMergedWithContactID > 0)) { Page.Response.Redirect(URLHelper.Url.ToString(), true); } else { gridElem.ReloadData(); } } } }
/// <summary> /// Creates temporary contact management - contact. Called when the "Create temporary objects" button is pressed. /// Expects the CreateTemporaryObjects method to be run first. /// </summary> private bool DeleteTemporaryObjects() { // Get dataset of contacts string where = "ContactLastName LIKE N'My New Contact%'"; var contacts = ContactInfoProvider.GetContacts().Where(where); if (!DataHelper.DataSourceIsEmpty(contacts)) { // Loop through the individual items foreach (ContactInfo contact in contacts) { // Delete the contact ContactInfoProvider.DeleteContactInfo(contact); } return(true); } return(false); }
private void ChangeStatus(What what) { int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); string where = null; switch (what) { case What.All: where = "ContactID IN (SELECT ContactGroupMemberRelatedID FROM OM_ContactGroupMember WHERE ContactGroupMemberContactGroupID = " + cgi.ContactGroupID + ")"; break; case What.Selected: where = SqlHelper.GetWhereCondition <int>("ContactID", gridElem.SelectedItems, false); break; } ContactInfoProvider.UpdateContactStatus(statusId, where); ShowConfirmation(GetString("om.contact.massaction.statuschanged")); }
private void btnSplit_Click(object sender, EventArgs e) { if (ContactHelper.AuthorizedModifyContact(Contact.ContactSiteID, true)) { if (gridElem.SelectedItems.Count > 0) { var contacts = ContactInfoProvider.GetContacts().WhereIn("ContactID", gridElem.SelectedItems.Select(c => c.ToInteger(0)).ToList()); ContactHelper.SplitContacts(Contact, contacts.ToList(), chkCopyMissingFields.Checked, chkCopyActivities.Checked, chkRemoveAccounts.Checked); gridElem.ReloadData(); gridElem.ClearSelectedItems(); ShowConfirmation(GetString("om.contact.splitting")); pnlUpdate.Update(); } else { ShowError(GetString("om.contact.selectcontactssplit")); } } }
/// <summary> /// Remove contact from process. Called when the "Remove contact from process" button is pressed. /// Expects the CreateAutomationState method to be run first. /// </summary> private bool RemoveContactFromProcess() { // Get dataset of contacts string where = "ContactLastName LIKE N'My New Contact%'"; int topN = 1; var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(topN); // Get the process WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation); if (DataHelper.DataSourceIsEmpty(contacts) || (process == null)) { return(false); } // Get the contact from dataset ContactInfo contact = contacts.First <ContactInfo>(); // Get the instance of automation manager AutomationManager manager = AutomationManager.GetInstance(CurrentUser); // Get the states var states = AutomationStateInfoProvider.GetAutomationStates() .WhereEquals("StateWorkflowID", process.WorkflowID) .WhereEquals("StateObjectID", contact.ContactID) .WhereEquals("StateObjectType", PredefinedObjectType.CONTACT); if (states.Any()) { // Loop through the individual items foreach (AutomationStateInfo state in states) { // Remove contact from process manager.RemoveProcess(contact, state); } return(true); } return(false); }
protected void Page_PreRender(object sender, EventArgs e) { // Check that the control is included in CMSPage (otherwise an exception is thrown on the Design tab) var page = Page as CMSPage; if (page == null) { return; } if (ContactGroup == null) { return; } // Disable refresh when status is ready as performance optimization timRefresh.Enabled = ContactGroup.ContactGroupStatus == ContactGroupStatusEnum.Rebuilding; if (ContactGroup.ContactGroupStatus == ContactGroupStatusEnum.Rebuilding) { lblRatio.Visible = false; lblCount.Visible = false; return; } int numberOfContacts = ContactGroupMemberInfoProvider.GetNumberOfContactsInGroup(ContactGroup.ContactGroupID); // Display number of contacts lblCount.InnerText = String.Format(GetString("om.contactgroup.numberofcontacts"), numberOfContacts); // Display ratio only for site group, since for global it would be difficult to compute if (!ContactGroup.IsGlobal) { // Display ratio of the number of contacts int totalContactCount = ContactInfoProvider.GetContacts() .Count; double ratio = (totalContactCount == 0) ? 0 : (double)numberOfContacts / totalContactCount * 100; lblRatio.InnerText = String.Format(GetString("om.contactgroup.numberofcontacts.ratio"), ratio); } }
/// <summary> /// On external databound. /// </summary> /// <param name="sender">Sender</param> /// <param name="sourceName">Source name</param> /// <param name="parameter">Parameter</param> private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { ImageButton btn = null; ContactInfo ci; switch (sourceName.ToLowerCSafe()) { case "edit": btn = ((ImageButton)sender); // Add ability to open contact details btn.Attributes.Add("onClick", "EditContact(" + btn.CommandArgument + "); return false;"); break; case "view": btn = (ImageButton)sender; btn.Attributes.Add("onClick", "ViewScoreDetail(" + btn.CommandArgument + "); return false;"); break; case "#contactfullname": ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0)); if (ci != null) { return(TextHelper.MergeIfNotEmpty(" ", ci.ContactFirstName, ci.ContactMiddleName, ci.ContactLastName)); } return(String.Empty); case "#statusdisplayname": ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0)); if (ci != null) { ContactStatusInfo statusInfo = ContactStatusInfoProvider.GetContactStatusInfo(ci.ContactStatusID); if (statusInfo != null) { return(HTMLHelper.HTMLEncode(statusInfo.ContactStatusDisplayName)); } } return(String.Empty); } return(null); }
/// <summary> /// Delete items one by one. /// </summary> private void DeleteItems() { var connectionString = new SqlConnectionStringBuilder(ConnectionHelper.GetConnection().DataConnection.ConnectionString); connectionString.ConnectTimeout = SQL_TIMEOUT; while (!DataHelper.DataSourceIsEmpty(ds)) { using (new CMSConnectionScope(connectionString.ToString(), true)) { // Delete the contacts foreach (DataRow dr in ds.Tables[0].Rows) { var ci = new ContactInfo(dr); AddLog((ci.ContactLastName + " " + ci.ContactFirstName).Trim()); ContactHelper.Delete(ci, chkChildren.Checked, chkMoveRelations.Checked); } } ds = ContactInfoProvider.GetContacts(WhereCondition, "ContactLastName", 500, null); } }
/// <summary> /// Generates contacts for customers. When database already contains contacts for given customers, new contatact is not created /// </summary> public IList <ContactInfo> Generate() { IList <ContactInfo> contacts; int numberOfContacts = ContactInfoProvider.GetContacts().Count; if (numberOfContacts < 50) { numberOfContacts = contactNames.Length; contacts = new List <ContactInfo>(); for (int i = 0; i < numberOfContacts; i++) { contacts.Add(CreateContact(contactNames[i])); } } else { contacts = ContactInfoProvider.GetContacts().ToList(); } return(contacts); }
/// <summary> /// Unigrid button clicked. /// </summary> protected void gridElem_OnAction(string actionName, object actionArgument) { // Perform 'remove' action if (actionName == "remove") { // Delete the object int contactId = ValidationHelper.GetInteger(actionArgument, 0); ContactInfo contact = ContactInfoProvider.GetContactInfo(contactId); if (contact != null) { CheckModifyPermissions(); // Get the relationship object ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, contactId, ContactGroupMemberTypeEnum.Contact); if (mi != null) { ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi); } } } }
private void UniSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions if (ContactHelper.AuthorizedModifyContact(ci.ContactSiteID, true)) { string values = ValidationHelper.GetString(selectUser.UniSelector.Value, null); if (!String.IsNullOrEmpty(values)) { // Store users one by one string[] userIds = values.Split(';'); foreach (string userId in userIds) { // Check if user ID is valid int userIdInt = ValidationHelper.GetInteger(userId, 0); if (userIdInt <= 0) { continue; } // Add new relation int parentId = (ci.ContactMergedWithContactID == 0) ? ci.ContactID : ci.ContactMergedWithContactID; MembershipInfoProvider.SetRelationship(userIdInt, MemberTypeEnum.CmsUser, ci.ContactID, parentId, true); // When contact was merged update contact info ci = ContactInfoProvider.GetContactInfo(contactId); } // When contact was merged then refresh complete page if ((ci != null) && (ci.ContactMergedWithContactID > 0)) { Page.Response.Redirect(URLHelper.Url.ToString(), true); } else { gridElem.ReloadData(); } } } }
/// <summary> /// Remove contact from process. Called when the "Remove contact from process" button is pressed. /// Expects the CreateAutomationState method to be run first. /// </summary> private bool RemoveContactFromProcess() { // Get dataset of contacts string where = "ContactLastName LIKE N'My New Contact%'"; int topN = 1; InfoDataSet <ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, topN, null); // Get the process WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation); if (!DataHelper.DataSourceIsEmpty(contacts) && (process != null)) { // Get the contact from dataset ContactInfo contact = contacts.First <ContactInfo>(); // Get the instance of automation manager AutomationManager manager = AutomationManager.GetInstance(CurrentUser); // Prepare the parameters where = "StateWorkflowID = " + process.WorkflowID + " AND StateObjectID = " + contact.ContactID + " AND StateObjectType = '" + PredefinedObjectType.CONTACT + "'"; // Get the states InfoDataSet <AutomationStateInfo> states = AutomationStateInfoProvider.GetStates(where, null); if (!DataHelper.DataSourceIsEmpty(states)) { // Loop through the individual items foreach (AutomationStateInfo state in states) { // Remove contact from process manager.RemoveProcess(contact, state); } return(true); } } return(false); }
private ContactInfo GenerateToddRay(int contactStatusId, int contactOwneruserId) { var contact = GenerateContact("Todd", "Ray", "*****@*****.**", "(808)-289-4459"); contact.ContactBirthday = DateTime.Today.AddYears(-42); contact.ContactGender = 1; contact.ContactJobTitle = OwnerContactRole; contact.ContactStatusID = contactStatusId; contact.ContactMobilePhone = "+420123456789"; contact.ContactCampaign = ContactCampaign; contact.ContactOwnerUserID = contactOwneruserId; contact.ContactCity = "Brno"; contact.ContactAddress1 = "Benesova 13"; contact.ContactZIP = "612 00"; contact.ContactCompanyName = "Air Cafe"; contact.ContactCountryID = CountryInfoProvider.GetCountryInfo("CzechRepublic").CountryID; contact.ContactNotes = "Should be involved in every communication with Air Cafe."; ContactInfoProvider.SetContactInfo(contact); GeneratePageVisitActivity(_mPartnershipDocument, contact); CreateFormSubmission(_mPartnershipDocument, BusinessCustomerRegistationFormCodeName, contact); return(contact); }
private void SetCustomerRelationAndUpdateContact(CustomerInfo customerInfo) { if (mCurrentContactProvider == null || mContactProcessingChecker == null) { return; } if (!mContactProcessingChecker.CanProcessContactInCurrentContext()) { return; } var currentContact = mCurrentContactProvider.GetCurrentContact(MembershipContext.AuthenticatedUser, false); mCurrentContactProvider.SetCurrentContact(currentContact); Service.Resolve <IContactRelationAssigner>().Assign(MemberTypeEnum.EcommerceCustomer, customerInfo, currentContact); ContactInfoProvider.UpdateContactFromExternalData( customerInfo, DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, currentContact.ContactID); }
private void StartNewProcess(What what, string where) { try { string error = String.Empty; int processId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); switch (what) { case What.All: // Get selected IDs based on where condition var contactIdsQuery = ContactGroupMemberInfoProvider.GetRelationships().Where(where).Column("ContactGroupMemberRelatedID"); var contactsQuery = ContactInfoProvider.GetContacts().WhereIn("ContactId", contactIdsQuery); error = ExecuteProcess(processId, contactsQuery); break; case What.Selected: var contactIds = gridElem.SelectedItems; var query = ContactInfoProvider.GetContacts().WhereIn("ContactId", contactIds); error = ExecuteProcess(processId, query); break; } if (String.IsNullOrEmpty(error)) { string confirmation = GetString(what == What.All ? "ma.process.started" : "ma.process.startedselected"); ShowConfirmation(confirmation); } else { ShowError(GetString("ma.process.error"), error, null); } } catch (Exception ex) { LogAndShowError("Automation", "STARTPROCESS", ex); } }
public void Evaluate_NoContactGroupSelected_ReturnsCorrectResult(int contactId, Constraint result) { var currentContact = ContactInfoProvider.GetContactInfo(contactId); currentContactProvider.GetCurrentContact(Arg.Any <IUserInfo>(), Arg.Any <bool>()) .Returns(currentContact); var evaluatorEmpty = new IsInContactGroupConditionType { SelectedContactGroups = new List <string>() }; var evaluatorNull = new IsInContactGroupConditionType { SelectedContactGroups = null }; Assert.Multiple(() => { Assert.That(() => evaluatorEmpty.Evaluate(), result); Assert.That(() => evaluatorNull.Evaluate(), result); }); }
private void GenerateMonicaKing() { var monicaKing = GenerateContact("Monica", "King", "*****@*****.**", "(595)-721-1648"); monicaKing.ContactBirthday = DateTime.Today.AddYears(-35); monicaKing.ContactGender = (int)UserGenderEnum.Female; monicaKing.ContactJobTitle = BARISTA_CONTACT_ROLE; monicaKing.ContactMobilePhone = "+420123456789"; monicaKing.ContactCity = "Brno"; monicaKing.ContactAddress1 = "New Market 187/5"; monicaKing.ContactZIP = "602 00"; monicaKing.ContactCompanyName = "Air Cafe"; monicaKing.ContactCountryID = CountryInfoProvider.GetCountryInfo("CzechRepublic").CountryID; monicaKing.ContactNotes = "Should be involved in every communication with Air Cafe."; ContactInfoProvider.SetContactInfo(monicaKing); GeneratePageVisitActivity(contactsDocument, monicaKing); GeneratePageVisitActivity(coffeeSamplesDocument, monicaKing); CreateFormSubmission(coffeeSamplesDocument, COFFEE_SAMPLE_LIST_FORM_CODE_NAME, monicaKing); CreateFormSubmission(contactsDocument, CONTACT_US_FORM_CODE_NAME, monicaKing); GeneratePurchaseActivity(20, monicaKing); }
/// <summary> /// On external databound. /// </summary> /// <param name="sender">Sender</param> /// <param name="sourceName">Source name</param> /// <param name="parameter">Parameter</param> private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { CMSGridActionButton btn; ContactInfo ci; switch (sourceName.ToLowerCSafe()) { case "edit": btn = (CMSGridActionButton)sender; // Ensure accountID parameter value; var objectID = ValidationHelper.GetInteger(btn.CommandArgument, 0); // Contact detail URL string contactURL = ApplicationUrlHelper.GetElementDialogUrl(ModuleName.CONTACTMANAGEMENT, "EditContact", objectID); // Add modal dialog script to onClick action btn.OnClientClick = ScriptHelper.GetModalDialogScript(contactURL, "ContactDetail"); break; case "view": btn = (CMSGridActionButton)sender; btn.OnClientClick = "ViewScoreDetail(" + btn.CommandArgument + "); return false;"; break; case "#statusdisplayname": ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0)); if (ci != null) { ContactStatusInfo statusInfo = ContactStatusInfoProvider.GetContactStatusInfo(ci.ContactStatusID); if (statusInfo != null) { return(HTMLHelper.HTMLEncode(statusInfo.ContactStatusDisplayName)); } } return(String.Empty); } return(null); }
private ContactInfo GenerateMonicaKing(int contactStatusId, int contactOwneruserId) { var contact = GenerateContact("Monica", "King", "*****@*****.**", "(595)-721-1648"); contact.ContactBirthday = DateTime.Today.AddYears(-35); contact.ContactGender = 2; contact.ContactJobTitle = BaristaContactRole; contact.ContactStatusID = contactStatusId; contact.ContactMobilePhone = "+420123456789"; contact.ContactCampaign = ContactCampaign; contact.ContactOwnerUserID = contactOwneruserId; contact.ContactCity = "Brno"; contact.ContactAddress1 = "New Market 187/5"; contact.ContactZIP = "602 00"; contact.ContactCompanyName = "Air Cafe"; contact.ContactCountryID = CountryInfoProvider.GetCountryInfo("CzechRepublic").CountryID; contact.ContactNotes = "Should be involved in every communication with Air Cafe."; ContactInfoProvider.SetContactInfo(contact); GeneratePageVisitActivity(_mPartnershipDocument, contact); CreateFormSubmission(_mPartnershipDocument, TryFreeSampleFormCodeName, contact); CreateFormSubmission(_mPartnershipDocument, ContactUsFormCodeName, contact); GeneratePurchaseActivity(20.0, contact); return(contact); }
/// <summary> /// Loads data of specific activity. /// </summary> protected void LoadData() { if (activityId <= 0) { return; } // Load and check if object exists ActivityInfo ai = ActivityInfo.Provider.Get(activityId); EditedObject = ai; ActivityTypeInfo ati = ActivityTypeInfo.Provider.Get(ai.ActivityType); plcActivityValue.Visible = (ati == null) || ati.ActivityTypeIsCustom || (ati.ActivityTypeName == PredefinedActivityType.PAGE_VISIT) && !String.IsNullOrEmpty(ai.ActivityValue); string dispName = (ati != null ? ati.ActivityTypeDisplayName : GetString("general.na")); lblTypeVal.Text = String.Format("{0}", HTMLHelper.HTMLEncode(dispName)); lblContactVal.Text = HTMLHelper.HTMLEncode(ContactInfoProvider.GetContactFullName(ai.ActivityContactID)); // Init contact detail link string contactURL = ApplicationUrlHelper.GetElementDialogUrl(ModuleName.CONTACTMANAGEMENT, "EditContact", ai.ActivityContactID); btnContact.Attributes.Add("onClick", ScriptHelper.GetModalDialogScript(contactURL, "ContactDetail")); btnContact.ToolTip = GetString("general.edit"); lblDateVal.Text = (ai.ActivityCreated == DateTimeHelper.ZERO_TIME ? GetString("general.na") : HTMLHelper.HTMLEncode(ai.ActivityCreated.ToString())); // Get site display name string siteName = SiteInfoProvider.GetSiteName(ai.ActivitySiteID); if (String.IsNullOrEmpty(siteName)) { siteName = GetString("general.na"); } else { // Retrieve site info and its display name SiteInfo si = SiteInfo.Provider.Get(siteName); if (si != null) { siteName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(si.DisplayName)); } else { siteName = GetString("general.na"); } } lblSiteVal.Text = siteName; string url = ai.ActivityURL; plcCampaign.Visible = !String.IsNullOrEmpty(ai.ActivityCampaign); lblCampaignVal.Text = HTMLHelper.HTMLEncode(ai.ActivityCampaign); lblValue.Text = HTMLHelper.HTMLEncode(String.IsNullOrEmpty(ai.ActivityValue) ? GetString("general.na") : ai.ActivityValue); // Init textboxes only for the first time if (!RequestHelper.IsPostBack()) { txtComment.Value = ai.ActivityComment; txtTitle.Text = ai.ActivityTitle; txtURLRef.Text = ai.ActivityURLReferrer; if (ai.ActivityType != PredefinedActivityType.NEWSLETTER_CLICKTHROUGH) { txtURL.Text = url; } } cDetails.ActivityID = activityId; // Init link button URL if (ai.ActivitySiteID > 0) { SiteInfo si = SiteInfo.Provider.Get(ai.ActivitySiteID); if (si != null) { // Hide view button if URL is blank string activityUrl = ai.ActivityURL; if ((activityUrl != null) && !String.IsNullOrEmpty(activityUrl.Trim())) { string appUrl = URLHelper.GetApplicationUrl(si.DomainName); url = URLHelper.GetAbsoluteUrl(activityUrl, appUrl, appUrl, ""); url = URLHelper.AddParameterToUrl(url, URLHelper.SYSTEM_QUERY_PARAMETER, "1"); btnView.ToolTip = GetString("general.view"); btnView.NavigateUrl = url; btnView.Visible = true; } else { btnView.Visible = false; } } } }
public void Merge(string userName) { Guard.ArgumentNotNullOrWhiteSpace(userName, nameof(userName)); try { string kenticoUserName = _kenticoUserNameNormalizer.Normalize(userName); if (!_contactProcessingChecker.Value.CanProcessContactInCurrentContext()) { return; } UserInfo userInfo = UserInfoProvider.GetUserInfo(kenticoUserName); if (userInfo == null) { return; } if (string.IsNullOrWhiteSpace(userInfo.Email)) { throw new KenticoContactException($"The specified user with userName: {kenticoUserName} does not have an email address specified."); } // Try and find a contact with a matching email for the current user ContactInfo currentContact = ContactInfoProvider.GetContactInfo(userInfo.Email); // Find the contact based on the current request. This is read from the CurrentContact cookie internally. ContactInfo cookieContact = _contactPersistentStorage.Value.GetPersistentContact(); // If a contact based on the CurrentContact cookie cannot be found, create a new anonymous one. // Such a scenario may present itself if the cookie has been tampered with or the contact no longer exists in Kentico. if (cookieContact == null) { cookieContact = _contactCreator.Value.CreateAnonymousContact(); } if (currentContact?.ContactEmail == cookieContact.ContactEmail) { // The current user already has a contact and the one on the cookie is the same // so we don't need to do anything else. return; } if (currentContact == null) { // The current user doesn't have a contact. If the one based on the cookie is anonymous though // we can use that and assign it to the user without creating a new one. if (cookieContact.ContactIsAnonymous) { currentContact = cookieContact; } else { // The contact retrieved based on the cookie value is for a different user. // We can't use that and that's the entire reason for having to write this class. currentContact = _contactCreator.Value.CreateAnonymousContact(); } // We should have a contact we can use now that does not yet have a user assigned to it. // Sanity check this assertion just in case though. if (currentContact.Users.Count > 0) { throw new KenticoContactException($"The current contact already has users assigned to it. This is not permitted. Id: {currentContact.ContactID}, GUID: {currentContact.ContactGUID}, Email: {currentContact.ContactEmail}"); } // This converts the anonymous contact into a real one for the user. _contactRelationAssigner.Value.Assign(userInfo, currentContact); } // Determine if we need to merge the current contact with the cookie one. if (currentContact != cookieContact && cookieContact.ContactIsAnonymous) { _contactMergeService.Value.MergeContacts(cookieContact, currentContact); } // Always ensure the correct contact is being used. // This has the effect of updating the contact id stored in the CurrentContact cookie // so all subsequent requests will be for the correct contact. _contactPersistentStorage.Value.SetPersistentContact(currentContact); } catch (Exception exc) when(_log.WriteError(exc, new { userName }, returnValue: true)) { throw new KenticoContactException("There has been a problem merging the contact data for the specified user.", exc); } }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { string resultMessage = string.Empty; // Get where condition depending on mass action selection string where; List <string> contactIds = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: // Get all contacts with scores based on filter condition var contacts = GetContactsWithScore(); if (!DataHelper.DataSourceIsEmpty(contacts)) { // Get array list with IDs contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true); } break; // Selected items case What.Selected: // Get selected IDs from unigrid contactIds = gridElem.SelectedItems; break; } // Prepare where condition if ((contactIds != null) && (contactIds.Count > 0)) { where = SqlHelper.GetWhereCondition <int>("ContactID", contactIds, false); } else { where = "0=1"; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { ContactInfoProvider.UpdateContactStatus(statusId, where); resultMessage = GetString("om.contact.massaction.statuschanged"); } break; // Action 'Add to contact group' case Action.AddToGroup: // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if ((groupId > 0) && (contactIds != null)) { // Add each selected contact to the contact group, skip contacts that are already members of the group foreach (string item in contactIds) { int contactId = ValidationHelper.GetInteger(item, 0); if (contactId > 0) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } } // Get contact group to show result message with its display name ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (group != null) { resultMessage = String.Format(GetString("om.contact.massaction.addedtogroup"), group.ContactGroupDisplayName); } } break; default: return; } if (!string.IsNullOrEmpty(resultMessage)) { lblInfo.Text = resultMessage; lblInfo.Visible = true; } // Reload unigrid gridElem.ClearSelectedItems(); gridElem.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { // Get where condition depending on mass action selection string where = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: where = SqlHelper.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause); break; // Selected items case What.Selected: where = SqlHelper.GetWhereCondition <int>("ContactID", gridElem.SelectedItems, false); break; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { ContactInfoProvider.UpdateContactStatus(statusId, where); ShowConfirmation(GetString("om.contact.massaction.statuschanged")); } break; // Action 'Add to contact group' case Action.AddToGroup: // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if (groupId > 0) { var contactGroup = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (contactGroup == null) { RedirectToAccessDenied(GetString("general.invalidparameters")); return; } if (contactGroup.ContactGroupSiteID != CurrentSite.SiteID) { RedirectToAccessDenied(GetString("general.invalidparameters")); return; } IEnumerable <string> contactIds = null; switch (what) { // All items case What.All: // Get selected IDs based on where condition DataSet contacts = ContactInfoProvider.GetContacts().Where(where).Column("ContactID"); if (!DataHelper.DataSourceIsEmpty(contacts)) { // Get array list with IDs contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true); } break; // Selected items case What.Selected: // Get selected IDs from unigrid contactIds = gridElem.SelectedItems; break; } if (contactIds != null) { // Add each selected contact to the contact group, skip contacts that are already members of the group foreach (string item in contactIds) { int contactId = item.ToInteger(0); if (contactId > 0) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } } // Show result message with contact group's display name ShowConfirmation(String.Format(GetString("om.contact.massaction.addedtogroup"), ResHelper.LocalizeString(contactGroup.ContactGroupDisplayName))); } } break; // Merge click case Action.Merge: DataSet selectedContacts = ContactHelper.GetContactListInfos(null, where, null, -1, null); if (!DataHelper.DataSourceIsEmpty(selectedContacts)) { // Get selected contact ID from hidden field int contactID = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If contact ID is 0 then new contact must be created if (contactID == 0) { int siteID; if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector) { siteID = filter.SelectedSiteID; } else { siteID = SiteID; } SetDialogParameters(selectedContacts, ContactHelper.GetNewContact(ContactHelper.MERGED, true, siteID)); } // Selected contact to be merged into else if (contactID > 0) { SetDialogParameters(selectedContacts, ContactInfoProvider.GetContactInfo(contactID)); } OpenWindow(); } break; default: return; } // Reload unigrid gridElem.ResetSelection(); gridElem.ReloadData(); pnlUpdate.Update(); }
private void StartNewProcess(What what, string where) { try { AutomationManager manager = AutomationManager.GetInstance(CurrentUser); List <string> contactIds = null; switch (what) { case What.All: // Get selected IDs based on where condition DataSet contacts = ContactGroupMemberInfoProvider.GetRelationships().Where(where).Column("ContactGroupMemberRelatedID"); if (!DataHelper.DataSourceIsEmpty(contacts)) { contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactGroupMemberRelatedID", true); } break; case What.Selected: contactIds = gridElem.SelectedItems; break; } if (contactIds != null) { string error = String.Empty; using (CMSActionContext context = new CMSActionContext()) { context.AllowAsyncActions = false; int processId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); foreach (string contactId in contactIds) { var contact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(contactId, 0)); try { manager.StartProcess(contact, processId); } catch (ProcessRecurrenceException ex) { error += "<div>" + ex.Message + "</div>"; } } } if (String.IsNullOrEmpty(error)) { string confirmation = GetString(what == What.All ? "ma.process.started" : "ma.process.startedselected"); ShowConfirmation(confirmation); } else { ShowError(GetString("ma.process.error"), error, null); } } } catch (Exception ex) { LogAndShowError("Automation", "STARTPROCESS", ex); } }
/// <summary> /// Returns SQL WHERE condition depending on selected checkboxes. /// </summary> /// <returns>Returns SQL WHERE condition</returns> public string GetWhereCondition() { string where = null; // Contacts checked if (chkContacts.Checked) { string contactWhere = null; ContactInfo contact; // Get primary contact WHERE condition if (this.CurrentAccount.AccountPrimaryContactID != 0) { contact = ContactInfoProvider.GetContactInfo(this.CurrentAccount.AccountPrimaryContactID); if (contact != null) { if (!String.IsNullOrEmpty(contact.ContactFirstName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "PrimaryContactFirstName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactFirstName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactMiddleName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "PrimaryContactMiddleName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactMiddleName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactLastName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "PrimaryContactLastName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactLastName, false) + "%'", "OR"); } } } // Get secondary contact WHERE condition if (this.CurrentAccount.AccountSecondaryContactID != 0) { contact = ContactInfoProvider.GetContactInfo(this.CurrentAccount.AccountSecondaryContactID); if (contact != null) { if (!String.IsNullOrEmpty(contact.ContactFirstName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "SecondaryContactFirstName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactFirstName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactMiddleName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "SecondaryContactMiddleName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactMiddleName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactLastName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "SecondaryContactLastName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactLastName, false) + "%'", "OR"); } } } if (!String.IsNullOrEmpty(contactWhere)) { where = SqlHelperClass.AddWhereCondition(where, contactWhere); } } // Address checked if (chkAddress.Checked) { string addressWhere = null; if (!String.IsNullOrEmpty(this.CurrentAccount.AccountAddress1)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountAddress1 LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountAddress1, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountAddress2)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountAddress2 LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountAddress2, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountCity)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountCity LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountCity, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountZIP)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountZIP LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountZIP, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(addressWhere)) { where = SqlHelperClass.AddWhereCondition(where, "(" + addressWhere + ")"); } } // Email address checked if (chkEmail.Checked && !String.IsNullOrEmpty(ContactHelper.GetEmailDomain(this.CurrentAccount.AccountEmail))) { string emailWhere = "(AccountEmail LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountEmail, false) + "%' OR AccountEmail LIKE '%" + SqlHelperClass.GetSafeQueryString(ContactHelper.GetEmailDomain(this.CurrentAccount.AccountEmail)) + "%')"; where = SqlHelperClass.AddWhereCondition(where, emailWhere); } // URL checked if (chkURL.Checked && !String.IsNullOrEmpty(this.CurrentAccount.AccountWebSite)) { string urlWhere = "(AccountWebSite LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountWebSite, false) + "%' OR AccountWebSite LIKE '%" + SqlHelperClass.GetSafeQueryString(URLHelper.CorrectDomainName(this.CurrentAccount.AccountWebSite)) + "%')"; where = SqlHelperClass.AddWhereCondition(where, urlWhere); } // Phone & fax checked if (chkPhone.Checked && (!String.IsNullOrEmpty(this.CurrentAccount.AccountPhone) || !String.IsNullOrEmpty(this.CurrentAccount.AccountFax))) { string phoneWhere = null; if (!String.IsNullOrEmpty(this.CurrentAccount.AccountPhone)) { phoneWhere = "AccountPhone LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountPhone, false) + "%'"; } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountFax)) { phoneWhere = SqlHelperClass.AddWhereCondition(phoneWhere, "AccountFax LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountFax, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(phoneWhere)) { where = SqlHelperClass.AddWhereCondition(where, "(" + phoneWhere + ")"); } } if ((!chkContacts.Checked && !chkAddress.Checked && !chkEmail.Checked && !chkURL.Checked && !chkPhone.Checked) || (String.IsNullOrEmpty(where))) { return("(1 = 0)"); } // Filter out current account where = SqlHelperClass.AddWhereCondition(where, "AccountID <> " + this.CurrentAccount.AccountID); // Filter out merged records where = SqlHelperClass.AddWhereCondition(where, "(AccountMergedWithAccountID IS NULL AND AccountGlobalAccountID IS NULL AND AccountSiteID > 0) OR (AccountGlobalAccountID IS NULL AND AccountSiteID IS NULL)"); // For global object use siteselector's value if (plcSite.Visible) { mSelectedSiteID = UniSelector.US_ALL_RECORDS; if (siteSelector.Visible) { mSelectedSiteID = siteSelector.SiteID; } else if (siteOrGlobalSelector.Visible) { mSelectedSiteID = siteOrGlobalSelector.SiteID; } // Only global objects if (mSelectedSiteID == UniSelector.US_GLOBAL_RECORD) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID IS NULL"); } // Global and site objects else if (mSelectedSiteID == UniSelector.US_GLOBAL_OR_SITE_RECORD) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID IS NULL OR AccountSiteID = " + CMSContext.CurrentSiteID); } // Site objects else if (mSelectedSiteID != UniSelector.US_ALL_RECORDS) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID = " + mSelectedSiteID); } } // Filter out accounts from different sites else { // Site accounts only if (this.CurrentAccount.AccountSiteID > 0) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID = " + this.CurrentAccount.AccountSiteID); } // Global accounts only else { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID IS NULL"); } } return(where); }
protected void Page_Load(object sender, EventArgs e) { // Register script for unimenu button selection AddMenuButtonSelectScript(this, "Contacts", null, "menu"); // Get current user info CurrentUserInfo user = CMSContext.CurrentUser; // Get contact info object ContactInfo ci = (ContactInfo)EditedObject; if (ci == null) { return; } // Check permission read ContactHelper.AuthorizedReadContact(ci.ContactSiteID, true); // Check if running under site manager (and distribute "site manager" flag to other tabs) string siteManagerParam = string.Empty; if (IsSiteManager) { siteManagerParam = "&issitemanager=1"; } // Set default help topic SetHelp("onlinemarketing_contact_general", "helpTopic"); // register scripts in modal dialog if (isDialogMode) { RegisterModalPageScripts(); } string append = null; if (ci.ContactMergedWithContactID != 0) { // Append '(merged)' behind contact name in breadcrumbs append = " " + GetString("om.contact.mergedsuffix"); } else if (ci.ContactSiteID == 0) { // Append '(global)' behind contact name in breadcrumbs append = " " + GetString("om.contact.globalsuffix"); } // Modify header appearance in modal dialog (display title instead of breadcrumbs) if (QueryHelper.GetBoolean("dialogmode", false)) { CurrentMaster.Title.TitleText = GetString("om.contact.edit") + " - " + HTMLHelper.HTMLEncode(ContactInfoProvider.GetContactFullName(ci)) + append; CurrentMaster.Title.TitleImage = GetImageUrl("Objects/OM_Contact/object.png"); } else { // Get url for breadcrumbs string url = ResolveUrl("~/CMSModules/ContactManagement/Pages/Tools/Contact/List.aspx"); url = URLHelper.AddParameterToUrl(url, "siteid", SiteID.ToString()); if (IsSiteManager) { url = URLHelper.AddParameterToUrl(url, "issitemanager", "1"); } CurrentPage.InitBreadcrumbs(2); CurrentPage.SetBreadcrumb(0, GetString("om.contact.list"), url, "_parent", null); CurrentPage.SetBreadcrumb(1, ContactInfoProvider.GetContactFullName(ci) + append, null, null, null); } // Check if contact has any custom fields int i = 0; FormInfo formInfo = FormHelper.GetFormInfo(ci.Generalized.DataClass.ClassName, false); if (formInfo.GetFormElements(true, false, true).Any()) { i = 1; } int contactId = ci.ContactID; bool ipTabAvailable = ActivitySettingsHelper.IPLoggingEnabled(CMSContext.CurrentSiteName) || ContactHelper.IsSiteManager; int counter = 0; // Initialize tabs InitTabs("content"); SetTab(counter++, GetString("general.general"), "Tab_General.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_general');"); if (i > 0) { // Add tab for custom fields SetTab(counter++, GetString("general.customfields"), "Tab_CustomFields.aspx?contactid=" + ci.ContactID + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_customfields');"); } if (AccountHelper.AuthorizedReadAccount(ci.ContactSiteID, false) || ContactHelper.AuthorizedReadContact(ci.ContactSiteID, false)) { SetTab(counter++, GetString("om.account.list"), "Tab_Accounts.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_accounts');"); } SetTab(counter++, GetString("om.membership.list"), "Membership/Tab_Membership.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_membership');"); SetTab(counter++, GetString("om.activity.list"), "Tab_Activities.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_activities');"); if (ipTabAvailable) { SetTab(counter++, GetString("om.activity.iplist"), "Tab_IPs.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_ips');"); } // Show contact groups SetTab(counter++, GetString("om.contactgroup.list"), "Tab_ContactGroups.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_contactgroups');"); // Show scoring tab for site contacts if (ci.ContactSiteID > 0) { SetTab(counter++, GetString("om.score.list"), "Tab_Scoring.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_scoring');"); } // Hide last 3 tabs if the contact is merged if (ci.ContactMergedWithContactID == 0) { SetTab(counter++, GetString("om.contact.merge"), "Tab_Merge.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_merge');"); } // Data.com SetTab(counter++, "Data.com", "Tab_DataCom.aspx?contactid=" + contactId + siteManagerParam, "SetHelpTopic('helpTopic', 'onlinemarketing_contact_datacom');"); // Marketing automation if (WorkflowInfoProvider.IsMarketingAutomationAllowed()) { string stateUrl = String.Format("{0}?objectid={1}{2}", "Tab_Processes.aspx", contactId, siteManagerParam); SetTab(counter++, GetString("ma.contact.processes"), stateUrl, "SetHelpTopic('helpTopic', 'automation_state_list');"); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; string siteName = SiteContext.CurrentSiteName; if ((txtCustomerCompany.Text.Trim() == "" || !IsBusiness) && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } // At least company name has to be filled when company account is selected if (errorMessage == "" && IsBusiness) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")).Result; } // Check the following items if complete company info is required for company account if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && IsBusiness) { errorMessage = new Validator().NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID")) .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result; } if (errorMessage == "") { errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat"), true) .MatchesCondition(txtCustomerPhone.Text.Trim(), k => k.Length < 50, GetString("customers_edit.errorphoneformat")).Result; } plcCompanyInfo.Visible = IsBusiness; if (errorMessage == "") { // If customer doesn't already exist, create new one if (mCustomer == null) { mCustomer = new CustomerInfo(); mCustomer.CustomerUserID = MembershipContext.AuthenticatedUser.UserID; } mCustomer.CustomerEmail = txtCustomerEmail.Text.Trim(); mCustomer.CustomerLastName = txtCustomerLastName.Text.Trim(); mCustomer.CustomerPhone = txtCustomerPhone.Text.Trim(); mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); mCustomer.CustomerCreated = DateTime.Now; if (IsBusiness) { mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim(); mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } else { mCustomer.CustomerCompany = ""; mCustomer.CustomerOrganizationID = ""; mCustomer.CustomerTaxRegistrationID = ""; } // Update customer data CustomerInfoProvider.SetCustomerInfo(mCustomer); // Update corresponding contact data int currentContactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingCreateRelation(mCustomer.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, currentContactId); ContactInfoProvider.UpdateContactFromExternalData( mCustomer, DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, currentContactId); // Let others now that customer was created if (OnCustomerCrated != null) { OnCustomerCrated(); ShowChangesSaved(); } else { URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1")); } } else { //Show error ShowError(errorMessage); } }
protected void Page_Load(object sender, EventArgs e) { // Check hash validity if (QueryHelper.ValidateHash("hash")) { // Initialize events ctlAsync.OnFinished += ctlAsync_OnFinished; ctlAsync.OnError += ctlAsync_OnError; ctlAsync.OnRequestLog += ctlAsync_OnRequestLog; ctlAsync.OnCancel += ctlAsync_OnCancel; issitemanager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false); if (!RequestHelper.IsCallback()) { // Setup page title text and image PageTitle.TitleText = GetString("om.contact.deletetitle"); btnCancel.Attributes.Add("onclick", ctlAsync.GetCancelScript(true) + "return false;"); titleElemAsync.TitleText = GetString("om.contact.deleting"); // Set visibility of panels pnlContent.Visible = true; pnlLog.Visible = false; // Get names of deleted contacts ds = ContactInfoProvider.GetContacts() .TopN(500) .Where(WhereCondition) .OrderBy("ContactLastName"); if (!DataHelper.DataSourceIsEmpty(ds)) { DataRowCollection rows = ds.Tables[0].Rows; // Data set contains only one item... if (rows.Count == 1) { // Get full contact name and use it in the title string fullName = GetFullName(rows[0]); if (!string.IsNullOrEmpty(fullName)) { PageTitle.TitleText += " \"" + HTMLHelper.HTMLEncode(fullName) + "\""; } contactSiteId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(rows[0], "ContactSiteID"), 0); } else if (rows.Count > 1) { // Modify title and question for multiple items PageTitle.TitleText = GetString("om.contact.deletetitlemultiple"); headQuestion.ResourceString = "om.contact.deletemultiplequestion"; // Display list with names of deleted items pnlContactList.Visible = true; string name = null; StringBuilder builder = new StringBuilder(); // Display top 500 records for (int i = 0; i < (rows.Count); i++) { builder.Append("<div>"); name = GetFullName(rows[i]); if (!string.IsNullOrEmpty(name)) { builder.Append(HTMLHelper.HTMLEncode(name)); } else { builder.Append("N/A"); } builder.Append("</div>"); } // Display three dots after last record if (rows.Count >= 500) { builder.Append("..."); } lblContacts.Text = builder.ToString(); contactSiteId = SiteID; } } else { // Hide everything pnlContent.Visible = false; } } } else { pnlDelete.Visible = false; ShowError(GetString("dialogs.badhashtext")); } }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { string resultMessage = string.Empty; // Get where condition depending on mass action selection string where = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: where = gridElem.WhereCondition; break; // Selected items case What.Selected: where = SqlHelperClass.GetWhereCondition <int>("ContactID", (string[])gridElem.SelectedItems.ToArray(typeof(string)), false); break; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentificator.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { ContactInfoProvider.UpdateContactStatus(statusId, where); resultMessage = GetString("om.contact.massaction.statuschanged"); } break; // Action 'Add to contact group' case Action.AddToGroup: // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentificator.Value, 0); if (groupId > 0) { ArrayList contactIds = null; switch (what) { // All items case What.All: // Get selected IDs based on where condition DataSet contacts = ContactInfoProvider.GetContacts(where, null, 0, "ContactID"); if (!DataHelper.DataSourceIsEmpty(contacts)) { // Get array list with IDs contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true); } break; // Selected items case What.Selected: // Get selected IDs from unigrid contactIds = gridElem.SelectedItems; break; } if (contactIds != null) { int contactId = 0; // Add each selected contact to the contact group, skip contacts that are already members of the group foreach (string item in contactIds) { contactId = ValidationHelper.GetInteger(item, 0); if (contactId > 0) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } } // Get contact group to show result message with its display name ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (group != null) { resultMessage = String.Format(GetString("om.contact.massaction.addedtogroup"), group.ContactGroupDisplayName); } } } break; // Merge click case Action.Merge: DataSet selectedContacts = ContactHelper.GetContactListInfos(null, where, null, -1, null); if (!DataHelper.DataSourceIsEmpty(selectedContacts)) { // Get selected contact ID from hidden field int contactID = ValidationHelper.GetInteger(hdnIdentificator.Value, -1); // If contact ID is 0 then new contact must be created if (contactID == 0) { int siteID; if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector) { siteID = filter.SelectedSiteID; } else { siteID = SiteID; } SetDialogParameters(selectedContacts, ContactHelper.GetNewContact(ContactHelper.MERGED, true, siteID)); } // Selected contact to be merged into else if (contactID > 0) { SetDialogParameters(selectedContacts, ContactInfoProvider.GetContactInfo(contactID)); } OpenWindow(); } break; default: return; } if (!string.IsNullOrEmpty(resultMessage)) { lblInfo.Text = resultMessage; lblInfo.Visible = true; } // Reload unigrid gridElem.ClearSelectedItems(); gridElem.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Sets primary and secondary contacts. /// </summary> private void AssignContacts() { ContactInfo contact; AccountContactInfo accountContact; // Assign primary contact to account and/or assign role int contactID = ValidationHelper.GetInteger(EditForm.EditedObject.GetValue("accountprimarycontactid"), -1); int contactRoleID = ValidationHelper.GetInteger(EditForm.FieldControls["accountprimarycontactroleid"].Value, -1); if (contactID > 0) { contact = ContactInfoProvider.GetContactInfo(contactID); if (contact != null) { accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, contactID); // Update relation if (accountContact != null) { accountContact.ContactRoleID = contactRoleID; AccountContactInfoProvider.SetAccountContactInfo(accountContact); } else { EditForm.EditedObject.SetValue("accountprimarycontactid", null); ((UniSelector)EditForm.FieldControls["accountprimarycontactid"]).Reload(true); } } // Selected contact doesn't exist else { ShowError(GetString("om.contact.primarynotexists")); return; } } // Assign secondary contact to account and/or assign role contactID = ValidationHelper.GetInteger(EditForm.EditedObject.GetValue("accountsecondarycontactid"), -1); contactRoleID = ValidationHelper.GetInteger(EditForm.FieldControls["accountsecondarycontactroleid"].Value, -1); // Assign secondary contact to account and/or assign role if (contactID > 0) { contact = ContactInfoProvider.GetContactInfo(contactID); if (contact != null) { accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, contactID); // Update relation if (accountContact != null) { accountContact.ContactRoleID = contactRoleID; AccountContactInfoProvider.SetAccountContactInfo(accountContact); } else { EditForm.EditedObject.SetValue("accountsecondarycontactid", null); ((UniSelector)EditForm.FieldControls["accountsecondarycontactid"]).Reload(true); } } else { ShowError(GetString("om.contact.secondarynotexists")); } } }