protected void BuyButton_Click(object sender, EventArgs e) { if (Contact != null) { try { ICredentialProvider credentialProvider = new UserCredentialProvider(MembershipContext.AuthenticatedUser); NetworkCredential userCredential = credentialProvider.GetCredential(); if (userCredential != null) { DataComClient client = DataComHelper.CreateClient(); 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); } } }
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(); DataComClient client = DataComHelper.CreateClient(); ICompanyProvider provider = DataComHelper.CreateCompanyProvider(client, configuration); Company company = provider.GetCompany(companyId); if (company != null) { CurrentCompany = company; } } catch (Exception exception) { HandleException(exception); } } } }
/// <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); } } }
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); }
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); }
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) { 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) { 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); } }