protected void Page_Load(object sender, EventArgs e) { try { RestoreParameters(); InitializeContactPreview(Contact); if (!RequestHelper.IsPostBack()) { ICredentialProvider credentialProvider = new UserCredentialProvider(MembershipContext.AuthenticatedUser); NetworkCredential userCredential = credentialProvider.GetCredential(); if (userCredential != null) { DataComClient client = DataComHelper.CreateClient(); User response = client.GetUser(userCredential); InitializeAccountPoints(response.Points); InitializePurchasePointsLink(DATACOM_LOGIN_PAGE); } else { ErrorSummary.Report(GetString("datacom.nousercredential")); BuyButton.Enabled = false; } } } catch (Exception exception) { HandleException(exception); } }
protected void CompanyGrid_OnAction(string actionName, object actionArgument) { if (actionName == "select") { long companyId = ValidationHelper.GetLong(actionArgument, 0); if (companyId > 0) { try { IDataComConfiguration configuration = DataComHelper.GetConfiguration(SiteIdentifierParameter); DataComClient client = DataComHelper.CreateClient(configuration); ICompanyProvider provider = DataComHelper.CreateCompanyProvider(client, configuration); Company company = provider.GetCompany(companyId); if (company != null) { CurrentCompany = company; } } catch (Exception exception) { HandleException(exception); } } } }
/// <summary> /// Checks whether is user has provided credential to DataCom or not. If not, user is redirected to login page. /// </summary> /// <exception cref="Exception">Might be thrown when error occurs in communicating with Data.com</exception> private bool CheckCredential() { var credential = credentialProvider.GetCredential(); var client = DataComHelper.CreateClient(); return(credential != null && client.UserIsValid(credential)); }
protected void BuyButton_Click(object sender, EventArgs e) { if (Contact != null) { try { IDataComConfiguration configuration = DataComHelper.GetConfiguration(SiteIdentifierParameter); NetworkCredential userCredential = configuration.GetUserCredential(); if (userCredential != null) { DataComClient client = DataComHelper.CreateClient(configuration); IContactProvider provider = new UserContactProvider(client, userCredential); Contact contact = provider.GetContact(Contact.ContactId, true); JsonSerializer serializer = new JsonSerializer(); ContactHiddenField.Value = serializer.Serialize(contact); } else { ErrorSummary.Report(GetString("datacom.nousercredential")); BuyButton.Enabled = false; } } catch (Exception exception) { HandleException(exception); } } }
/// <summary> /// Creates a list of localized attribute name/display value pairs for the specified Data.com contact, and returns it. /// </summary> /// <returns>A list of localized attribute name/display value pairs for the specified Data.com contact.</returns> private List <RepeaterDataItem> CreateDataSource() { IEntityAttributeFormatter formatter = DataComHelper.GetEntityAttributeFormatter(); List <RepeaterDataItem> items = new List <RepeaterDataItem>(); EntityInfo entityInfo = DataComHelper.GetContactEntityInfo(); IEntityAttributeMapperFactory entityAttributeFactory = DataComHelper.GetContactAttributeMapperFactory(); foreach (EntityAttributeInfo entityAttributeInfo in entityInfo.Items) { string entityAttributeValue = String.Empty; EntityAttributeMapperBase entityAttribute = entityAttributeFactory.CreateEntityAttributeMapper(entityAttributeInfo.Name, entityInfo); if (entityAttribute != null) { entityAttributeValue = entityAttribute.GetEntityAttributeDisplayValue(Contact, formatter); } RepeaterDataItem item = new RepeaterDataItem() { AttributeName = ResHelper.LocalizeString(entityAttributeInfo.DisplayName), AttributeValue = entityAttributeValue }; items.Add(item); } return(items); }
protected void Page_Load(object sender, EventArgs e) { try { RestoreParameters(); InitializeContactPreview(Contact); if (!RequestHelper.IsPostBack()) { IDataComConfiguration configuration = DataComHelper.GetConfiguration(SiteIdentifierParameter); NetworkCredential userCredential = configuration.GetUserCredential(); if (userCredential != null) { DataComClient client = DataComHelper.CreateClient(configuration); User response = client.GetUser(userCredential); InitializeAccountPoints(response.Points); InitializePurchasePointsLink(response.PurchasePointsUrl); } else { ErrorSummary.Report(GetString("datacom.nousercredential")); BuyButton.Enabled = false; } } } catch (Exception exception) { HandleException(exception); } }
protected void btnLogin_Click(object sender, EventArgs e) { var email = txtEmail.Text; var password = txtPassword.Text; if (!ValidationHelper.IsEmail(email)) { ShowError(GetString("datacom.invalidemail")); return; } if (string.IsNullOrEmpty(password)) { ShowError(GetString("general.requirespassword")); return; } var networkCredetial = new NetworkCredential { UserName = email, Password = password }; // Check if user is valid on data.com try { var client = DataComHelper.CreateClient(); if (!client.UserIsValid(networkCredetial)) { ShowError(GetString("datacom.invalidcredential")); return; } } catch (Exception ex) { ErrorSummary.Report(ex); return; } var redirectUrl = GetRedirectUrl(); if (redirectUrl != null) { var provider = GetCredentialProvider(); if (provider != null) { provider.SetCredential(networkCredetial); URLHelper.Redirect(UrlResolver.ResolveUrl(redirectUrl)); } else { // Someone has changed url or step has been deleted, url is no longer valid ShowError(GetString("datacom.invalidreferring")); } } else { ShowError(GetString("datacom.invalidreferring")); } }
/// <summary> /// Checks if given user's DataCom credentials are valid. Makes API call to Data.com service. /// </summary> /// <param name="user">User to check credentials for</param> /// <rereturns>Returns true if valid</rereturns> private bool CheckCredential(NetworkCredential credential) { if (credential == null || String.IsNullOrEmpty(credential.UserName)) { return false; } DataComClient client = DataComHelper.CreateClient(); return client.UserIsValid(credential); }
protected void Page_Load(object sender, EventArgs e) { AccountInfo account = EditedObject as AccountInfo; AuthorizeReadRequest(account); IDataComConfiguration configuration = DataComHelper.GetConfiguration(AccountSiteID); if (configuration.GetToken() == null) { ShowWarning(GetString("datacom.notoken"), null, null); } else { try { if (!String.IsNullOrEmpty(CompanyHiddenField.Value)) { JsonSerializer serializer = new JsonSerializer(); Company freshCompany = serializer.Unserialize <Company>(CompanyHiddenField.Value); if (Company == null || Company.CompanyId != freshCompany.CompanyId) { CompanyForm.MergeHint = true; } Company = freshCompany; } if (Company == null) { AccountInfo accountInfo = EditedObject as AccountInfo; CompanyIdentity identity = DataComHelper.CreateCompanyIdentity(accountInfo); DataComClient client = DataComHelper.CreateClient(configuration); ICompanyProvider provider = DataComHelper.CreateCompanyProvider(client, configuration); CompanyFinder finder = DataComHelper.CreateCompanyFinder(provider); CompanyFilter filterHint = null; Company match = finder.Find(identity, out filterHint); if (match != null) { ShowInformation(GetString("datacom.companymatch")); Company = match; CompanyForm.MergeHint = true; } else { ShowInformation(GetString("datacom.nocompanymatch")); } Filter = filterHint; } InitializeHeaderActions(); InitializeDataComForm(); } catch (Exception exception) { HandleException(exception); } } }
/// <summary> /// Initializes the form with the required dependencies and the specified CMS account. /// </summary> protected void InitializeDataComForm() { IDataComConfiguration configuration = DataComHelper.GetConfiguration(AccountSiteID); AccountInfo accountInfo = EditedObject as AccountInfo; CompanyForm.FormInformation = DataComHelper.GetAccountFormInfo(); CompanyForm.EntityInfo = DataComHelper.GetCompanyEntityInfo(configuration); CompanyForm.EntityMapping = configuration.GetCompanyMapping(); CompanyForm.EntityAttributeMapperFactory = DataComHelper.GetCompanyAttributeMapperFactory(); CompanyForm.Entity = Company; CompanyForm.EntityAttributeFormatter = DataComHelper.GetEntityAttributeFormatter(); CompanyForm.Restore(accountInfo); }
protected DataSet ContactGrid_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords) { try { ICredentialProvider credentialProvider = new UserCredentialProvider(MembershipContext.AuthenticatedUser); DataComClient client = DataComHelper.CreateClient(); IContactProvider provider = DataComHelper.CreateContactProvider(client, credentialProvider.GetCredential()); ContactSearchResults response = provider.SearchContacts(CurrentContactFilter, currentOffset / currentPageSize, currentPageSize); DataTable table = new DataTable("Contacts"); table.Columns.Add("ContactId", typeof(long)); table.Columns.Add("FirstName", typeof(string)); table.Columns.Add("LastName", typeof(string)); table.Columns.Add("CompanyName", typeof(string)); foreach (Contact contact in response.Contacts) { DataRow row = table.NewRow(); row["ContactId"] = contact.ContactId; row["FirstName"] = contact.FirstName; row["LastName"] = contact.LastName; row["CompanyName"] = contact.CompanyName; table.Rows.Add(row); if (contact.ContactId == CurrentContactId) { CurrentContact = contact; } } DataSet dataSet = new DataSet(); dataSet.Tables.Add(table); int maxHitCount = currentPageSize * MAX_PAGE_COUNT; int hitCount = (int)response.TotalHits; if (hitCount > maxHitCount) { hitCount = maxHitCount; ShowWarning(GetString("datacom.toomanycontacts"), null, null); } totalRecords = hitCount; return(dataSet); } catch (Exception exception) { HandleException(exception); } totalRecords = 0; return(null); }
/// <summary> /// Initializes the form with the required dependencies and the specified CMS contact. /// </summary> protected void InitializeDataComForm() { IDataComConfiguration configuration = DataComHelper.GetConfiguration(); ContactInfo contactInfo = EditedObject as ContactInfo; ContactForm.ParametersIdentifier = BuyParametersIdentifier; ContactForm.FormInformation = DataComHelper.GetContactFormInfo(); ContactForm.EntityInfo = DataComHelper.GetContactEntityInfo(); ContactForm.EntityMapping = configuration.GetContactMapping(); ContactForm.EntityAttributeMapperFactory = DataComHelper.GetContactAttributeMapperFactory(); ContactForm.Entity = Contact; ContactForm.EntityAttributeFormatter = DataComHelper.GetEntityAttributeFormatter(); ContactForm.BuyContactEnabled = (credentialProvider.GetCredential() != null); ContactForm.DefaultFieldLayout = FieldLayoutEnum.ThreeColumns; ContactForm.DefaultFormLayout = FormLayoutEnum.SingleTable; ContactForm.Restore(contactInfo); }
protected override void OnPreRender(EventArgs e) { if (Mapping != null) { try { FormInfo formInfo = DataComHelper.GetContactFormInfo(); EntityInfo entityInfo = DataComHelper.GetContactEntityInfo(); Panel mappingPanel = CreateMappingPanel(formInfo, entityInfo, Mapping); Controls.Add(mappingPanel); } catch (Exception exception) { HandleException(exception); } } base.OnPreRender(e); }
protected override void OnPreRender(EventArgs e) { if (Mapping != null) { try { IDataComConfiguration configuration = DataComHelper.GetConfiguration(CMSContext.CurrentSiteID); FormInfo formInfo = DataComHelper.GetAccountFormInfo(); EntityInfo entityInfo = DataComHelper.GetCompanyEntityInfo(configuration); HtmlTable table = CreateTable(formInfo, entityInfo, Mapping); Controls.Add(table); } catch (Exception exception) { HandleException(exception); } } base.OnPreRender(e); }
protected DataSet CompanyGrid_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords) { try { IDataComConfiguration configuration = DataComHelper.GetConfiguration(SiteIdentifierParameter); DataComClient client = DataComHelper.CreateClient(configuration); ICompanyProvider provider = DataComHelper.CreateCompanyProvider(client, configuration); CompanySearchResults response = provider.SearchCompanies(CurrentCompanyFilter, currentOffset / currentPageSize, currentPageSize); DataTable table = new DataTable("Companies"); table.Columns.Add("CompanyId", typeof(long)); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Country", typeof(string)); table.Columns.Add("City", typeof(string)); foreach (CompanySearchResult result in response.Results) { DataRow row = table.NewRow(); row["CompanyId"] = result.CompanyId; row["Name"] = result.Name; row["Country"] = result.Country; row["City"] = result.City; table.Rows.Add(row); } DataSet dataSet = new DataSet(); dataSet.Tables.Add(table); int maxHitCount = currentPageSize * MAX_PAGE_COUNT; int hitCount = (int)response.TotalHits; if (hitCount > maxHitCount) { hitCount = maxHitCount; ShowWarning(GetString("datacom.toomanycompanies"), null, null); } totalRecords = hitCount; return(dataSet); } catch (Exception exception) { HandleException(exception); } totalRecords = 0; return(null); }
/// <summary> /// Adds actions to the page header. /// </summary> protected void InitializeHeaderActions() { IDataComConfiguration configuration = DataComHelper.GetConfiguration(ContactSiteID); bool searchEnabled = (configuration.GetToken() != null); string[,] actions = new string[1 + (searchEnabled ? 1 : 0), 11]; actions[0, 0] = CMS.ExtendedControls.HeaderActions.TYPE_SAVEBUTTON; actions[0, 1] = GetString("general.apply"); actions[0, 5] = GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png"); actions[0, 6] = "save"; actions[0, 8] = "true"; if (searchEnabled) { actions[1, 0] = CMS.ExtendedControls.HeaderActions.TYPE_LINKBUTTON; actions[1, 1] = GetString("general.search"); actions[1, 2] = CreateSearchActionClientScript(); actions[1, 5] = GetImageUrl("CMSModules/CMS_ContactManagement/search.png"); } HeaderActions.ActionPerformed += HeaderActions_ActionPerformed; HeaderActions.Actions = actions; }
/// <summary> /// Creates current request context, and returns it. /// </summary> /// <returns>Current request context.</returns> private RequestContext CreateContext() { if (mEntityName == "Contact") { return(new RequestContext { FormInfo = DataComHelper.GetContactFormInfo(), EntityInfo = DataComHelper.GetContactEntityInfo(), InitializeMappingControl = (x => ContactMappingControl.Mapping = x) }); } if (mEntityName == "Company") { IDataComConfiguration configuration = DataComHelper.GetConfiguration(); return(new RequestContext { FormInfo = DataComHelper.GetAccountFormInfo(), EntityInfo = DataComHelper.GetCompanyEntityInfo(configuration), InitializeMappingControl = (x => CompanyMappingControl.Mapping = x) }); } throw new Exception(String.Format("[DataComEditMappingPage.CreateContext]: Invalid mapping type ({0}).", mEntityName)); }
protected void Page_Load(object sender, EventArgs e) { ContactInfo contact = EditedObject as ContactInfo; AuthorizeReadRequest(contact); IDataComConfiguration configuration = DataComHelper.GetConfiguration(ContactSiteID); if (configuration.GetToken() == null) { ShowWarning(GetString("datacom.notoken"), null, null); } else { try { if (!String.IsNullOrEmpty(ContactHiddenField.Value)) { JsonSerializer serializer = new JsonSerializer(); Contact freshContact = serializer.Unserialize <Contact>(ContactHiddenField.Value); if (Contact == null) { ContactForm.MergeHint = true; } else { if (Contact.ContactId != freshContact.ContactId) { ContactForm.MergeHint = true; } else if (String.IsNullOrEmpty(Contact.Phone) && String.IsNullOrEmpty(Contact.Email) && (!String.IsNullOrEmpty(freshContact.Phone) || !String.IsNullOrEmpty(freshContact.Email))) { ContactForm.MergeHint = true; ContactForm.MergeHintAttributes = new string[] { "Phone", "Email" }; } } Contact = freshContact; } if (Contact == null) { ContactInfo contactInfo = EditedObject as ContactInfo; ContactIdentity identity = DataComHelper.CreateContactIdentity(contactInfo); DataComClient client = DataComHelper.CreateClient(configuration); IContactProvider provider = DataComHelper.CreateContactProvider(client, configuration); ContactFinder finder = DataComHelper.CreateContactFinder(provider); ContactFilter filterHint = null; Contact match = finder.Find(identity, out filterHint); if (match != null) { ShowInformation(GetString("datacom.contactmatch")); Contact = match; ContactForm.MergeHint = true; } else { ShowInformation(GetString("datacom.nocontactmatch")); } Filter = filterHint; } InitializeHeaderActions(); InitializeDataComForm(); } catch (Exception exception) { HandleException(exception); } } }
protected void Page_Load(object sender, EventArgs e) { // Do not check login if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method) if (!RequestHelper.IsCallback()) { bool validCredential = false; try { validCredential = CheckCredential(); } catch (Exception ex) { HandleException(ex); return; } if (!validCredential) { URLHelper.Redirect(UrlResolver.ResolveUrl(LoginPageUrl)); } } try { if (!String.IsNullOrEmpty(ContactHiddenField.Value)) { JsonSerializer serializer = new JsonSerializer(); Contact freshContact = serializer.Unserialize <Contact>(ContactHiddenField.Value); if (Contact == null) { ContactForm.MergeHint = true; } else { if (Contact.ContactId != freshContact.ContactId) { ContactForm.MergeHint = true; } else if (String.IsNullOrEmpty(Contact.Phone) && String.IsNullOrEmpty(Contact.Email) && (!String.IsNullOrEmpty(freshContact.Phone) || !String.IsNullOrEmpty(freshContact.Email))) { ContactForm.MergeHint = true; ContactForm.MergeHintAttributes = new string[] { "Phone", "Email" }; } } Contact = freshContact; } ContactInfo contactInfo = EditedObject as ContactInfo; ContactIdentity identity = DataComHelper.CreateContactIdentity(contactInfo); Filter = identity.CreateFilter(); // Do not search for contact if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method) if (Contact == null && !RequestHelper.IsCallback()) { DataComClient client = DataComHelper.CreateClient(); IContactProvider provider = DataComHelper.CreateContactProvider(client, credentialProvider.GetCredential()); ContactFinder finder = DataComHelper.CreateContactFinder(provider); Contact match = finder.Find(identity); if (match != null) { ShowInformation(GetString("datacom.contactmatch")); Contact = match; ContactForm.MergeHint = true; } else { ShowInformation(GetString("datacom.nocontactmatch")); } } InitializeHeaderActions(); InitializeDataComForm(); } catch (Exception exception) { HandleException(exception); } }
protected void Page_Load(object sender, EventArgs e) { IDataComConfiguration configuration = DataComHelper.GetConfiguration(AccountSiteID); // Do not check login if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method) if (!RequestHelper.IsCallback()) { bool validCredential = false; try { validCredential = CheckCredential(); } catch (Exception ex) { HandleException(ex); return; } if (!validCredential) { URLHelper.Redirect(LoginPageUrl); } } try { if (!String.IsNullOrEmpty(CompanyHiddenField.Value)) { JsonSerializer serializer = new JsonSerializer(); Company freshCompany = serializer.Unserialize <Company>(CompanyHiddenField.Value); if (Company == null || Company.CompanyId != freshCompany.CompanyId) { CompanyForm.MergeHint = true; } Company = freshCompany; } AccountInfo accountInfo = EditedObject as AccountInfo; CompanyIdentity identity = DataComHelper.CreateCompanyIdentity(accountInfo); Filter = identity.CreateFilter(); // Do not search for company if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method) if (Company == null && !RequestHelper.IsCallback()) { DataComClient client = DataComHelper.CreateClient(); ICompanyProvider provider = DataComHelper.CreateCompanyProvider(client, configuration); CompanyFinder finder = DataComHelper.CreateCompanyFinder(provider); CompanyFilter filterHint = null; Company match = finder.Find(identity, out filterHint); if (match != null) { ShowInformation(GetString("datacom.companymatch")); Company = match; CompanyForm.MergeHint = true; } else { ShowInformation(GetString("datacom.nocompanymatch")); } } InitializeHeaderActions(); InitializeDataComForm(); } catch (Exception exception) { HandleException(exception); } }