/// <summary> /// Unigrid button clicked. /// </summary> protected void gridElem_OnAction(string actionName, object actionArgument) { if (actionName == "remove") { // User has permission modify if (mModifyAccountContact) { int relationId = ValidationHelper.GetInteger(actionArgument, 0); AccountContactInfo relation = AccountContactInfoProvider.GetAccountContactInfo(relationId); if (relation != null) { // We need to invalidate the contact as we might have modified some of its relationships and data in the cache might not be valid AccountContactInfoProvider.DeleteAccountContactInfo(relation); } } // User doesn't have sufficient permissions else { if (SiteID > 0) { CMSPage.RedirectToAccessDenied(ModuleName.CONTACTMANAGEMENT, "ModifyContacts"); } else { CMSPage.RedirectToAccessDenied(ModuleName.CONTACTMANAGEMENT, "ModifyGlobalContacts"); } } } }
/// <summary> /// Sets primary and secondary contacts. /// </summary> private bool AssignContacts() { ContactInfo contact = null; AccountContactInfo accountContact = null; // Assign primary contact to account and/or assign role if (primaryContact.ContactID > 0) { contact = ContactInfoProvider.GetContactInfo(primaryContact.ContactID); if (contact != null) { // Check if contact <-> account relation is already created accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, primaryContact.ContactID); // Update relation if (accountContact != null) { accountContact.ContactRoleID = contactRolePrimary.ContactRoleID; } AccountContactInfoProvider.SetAccountContactInfo(accountContact); } // Selected contact doesn't exist else { ShowError(GetString("om.contact.primarynotexists")); return(false); } } // Assign secondary contact to account and/or assign role if (secondaryContact.ContactID > 0) { contact = ContactInfoProvider.GetContactInfo(secondaryContact.ContactID); if (contact != null) { // Check if contact <-> account relation is already created accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, secondaryContact.ContactID); // Update relation if (accountContact != null) { accountContact.ContactRoleID = contactRoleSecondary.ContactRoleID; } AccountContactInfoProvider.SetAccountContactInfo(accountContact); } else { ShowError(GetString("om.contact.secondarynotexists")); return(false); } } return(true); }
protected void Page_Load(object sender, EventArgs e) { if (!QueryHelper.ValidateHash("hash") || Parameters == null) { StopProcessing = true; return; } PageTitle.TitleText = GetString("om.contactrole.selectitem"); Page.Title = PageTitle.TitleText; // Check if the dialog was opened from mass actions isMassAction = Parameters.ContainsKey("ismassaction"); if (isMassAction) { siteId = ValidationHelper.GetInteger(Parameters["siteid"], 0); } else { int accountContactId = ValidationHelper.GetInteger(Parameters["accountcontactid"], 0); aci = AccountContactInfoProvider.GetAccountContactInfo(accountContactId); if (aci != null) { AccountInfo ai = AccountInfoProvider.GetAccountInfo(aci.AccountID); if (ai != null) { siteId = ai.AccountSiteID; } } } // Show all global configuration to authorized users .. bool allowGlobal = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false); // .. but just in SiteManager - fake it in CMSDesk so that even Global Admin sees user configuration // as Site Admins (depending on settings). bool isSiteManager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false); allowGlobal &= (isSiteManager || SettingsKeyInfoProvider.GetBoolValue(SiteInfoProvider.GetSiteName(siteId) + ".cmscmglobalconfiguration")); bool allowSite; if (siteId > 0) { allowSite = ConfigurationHelper.AuthorizedReadConfiguration(siteId, false); } else { allowSite = ConfigurationHelper.AuthorizedReadConfiguration(SiteContext.CurrentSiteID, false); } // Check read permission if ((siteId > 0) && !allowSite && !allowGlobal) { RedirectToAccessDenied("cms.contactmanagement", "ReadConfiguration"); return; } else if ((siteId == 0) && !allowGlobal) { RedirectToAccessDenied("cms.contactmanagement", "ReadGlobalConfiguration"); return; } if (siteId > 0) { if (allowSite) { gridElem.WhereCondition = "ContactRoleSiteID = " + siteId; } // Check if global config is allowed for the site if (allowGlobal) { // Add contact roles from global configuration gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, "ContactRoleSiteID IS NULL", "OR"); } } else if ((siteId == 0) && allowGlobal) { gridElem.WhereCondition = "ContactRoleSiteID IS NULL"; } gridElem.OnExternalDataBound += gridElem_OnExternalDataBound; gridElem.Pager.DefaultPageSize = 10; // Display 'Reset' button when 'none' role is allowed if (ValidationHelper.GetBoolean(Parameters["allownone"], false)) { btnReset.Visible = true; btnReset.Click += btn_Click; btnReset.CommandArgument = "0"; } }
/// <summary> /// Adds contact under account. /// </summary> private bool AddContactToAccount() { // Get dataset of contacts string where = "ContactLastName LIKE N'My New Contact%'"; InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null); // Get dataset of accounts InfoDataSet<AccountInfo> accounts = AccountInfoProvider.GetAccounts("AccountName = 'My New Account'", null); // Get the role ContactRoleInfo role = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", CMSContext.CurrentSiteName); if (!DataHelper.DataSourceIsEmpty(contacts) && (!DataHelper.DataSourceIsEmpty(accounts)) && (role != null)) { // Get the contact from dataset ContactInfo contact = contacts.First<ContactInfo>(); // Get the account from dataset AccountInfo account = accounts.First<AccountInfo>(); // Create new account - contact relationship AccountContactInfo accountContact = new AccountContactInfo() { AccountID = account.AccountID, ContactID = contact.ContactID, ContactRoleID = role.ContactRoleID }; // And save it AccountContactInfoProvider.SetAccountContactInfo(accountContact); return true; } return false; }
protected void Page_Load(object sender, EventArgs e) { CurrentMaster.Title.TitleText = GetString("om.contactrole.select"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/OM_ContactRole/object.png"); Page.Title = CurrentMaster.Title.TitleText; string siteName = SiteInfoProvider.GetSiteName(siteId); CurrentUserInfo user = CMSContext.CurrentUser; if (!QueryHelper.ValidateHash("hash") || Parameters == null) { StopProcessing = true; return; } // Check if the dialog was opened from mass actions isMassAction = Parameters.ContainsKey("ismassaction"); isSitemanager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false); if (isMassAction) { siteId = ValidationHelper.GetInteger(Parameters["siteid"], 0); } else { int accountContactId = ValidationHelper.GetInteger(Parameters["accountcontactid"], 0); aci = AccountContactInfoProvider.GetAccountContactInfo(accountContactId); if (aci != null) { AccountInfo ai = AccountInfoProvider.GetAccountInfo(aci.AccountID); if (ai != null) { siteId = ai.AccountSiteID; } } } if (siteId < 0) { StopProcessing = true; return; } allowGlobal = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false, isSitemanager); if (siteId > 0) { allowSite = ConfigurationHelper.AuthorizedReadConfiguration(siteId, false); } else { allowSite = ConfigurationHelper.AuthorizedReadConfiguration(CMSContext.CurrentSiteID, false); } // Check read permission if ((siteId > 0) && !allowSite && !allowGlobal) { RedirectToAccessDenied("cms.contactmanagement", "ReadConfiguration"); return; } else if ((siteId == 0) && !allowGlobal) { RedirectToAccessDenied("cms.contactmanagement", "ReadGlobalConfiguration"); return; } if (siteId > 0) { if (allowSite) { gridElem.WhereCondition = "ContactRoleSiteID = " + siteId; } // Check if global config is allowed for the site if (allowGlobal) { // Add contact roles from global configuration gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, "ContactRoleSiteID IS NULL", "OR"); } } else if ((siteId == 0) && allowGlobal) { gridElem.WhereCondition = "ContactRoleSiteID IS NULL"; } gridElem.OnExternalDataBound += gridElem_OnExternalDataBound; gridElem.Pager.DefaultPageSize = 10; // Display 'Reset' button when 'none' role is allowed if (ValidationHelper.GetBoolean(Parameters["allownone"], false)) { btnReset.Visible = true; btnReset.Click += btn_Click; btnReset.CommandArgument = "0"; } }
protected void Page_Load(object sender, EventArgs e) { if (!QueryHelper.ValidateHash("hash") || Parameters == null) { StopProcessing = true; return; } PageTitle.TitleText = GetString("om.contactrole.select"); Page.Title = PageTitle.TitleText; // Check if the dialog was opened from mass actions isMassAction = Parameters.ContainsKey("ismassaction"); if (isMassAction) { siteId = ValidationHelper.GetInteger(Parameters["siteid"], 0); } else { int accountContactId = ValidationHelper.GetInteger(Parameters["accountcontactid"], 0); aci = AccountContactInfoProvider.GetAccountContactInfo(accountContactId); if (aci != null) { AccountInfo ai = AccountInfoProvider.GetAccountInfo(aci.AccountID); if (ai != null) { siteId = ai.AccountSiteID; } } } // Show all global configuration to authorized users .. bool allowGlobal = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false); // .. but just in SiteManager - fake it in CMSDesk so that even Global Admin sees user configuration // as Site Admins (depending on settings). bool isSiteManager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false); allowGlobal &= (isSiteManager || SettingsKeyInfoProvider.GetBoolValue(SiteInfoProvider.GetSiteName(siteId) + ".cmscmglobalconfiguration")); bool allowSite; if (siteId > 0) { allowSite = ConfigurationHelper.AuthorizedReadConfiguration(siteId, false); } else { allowSite = ConfigurationHelper.AuthorizedReadConfiguration(SiteContext.CurrentSiteID, false); } // Check read permission if ((siteId > 0) && !allowSite && !allowGlobal) { RedirectToAccessDenied("cms.contactmanagement", "ReadConfiguration"); return; } else if ((siteId == 0) && !allowGlobal) { RedirectToAccessDenied("cms.contactmanagement", "ReadGlobalConfiguration"); return; } if (siteId > 0) { if (allowSite) { gridElem.WhereCondition = "ContactRoleSiteID = " + siteId; } // Check if global config is allowed for the site if (allowGlobal) { // Add contact roles from global configuration gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, "ContactRoleSiteID IS NULL", "OR"); } } else if ((siteId == 0) && allowGlobal) { gridElem.WhereCondition = "ContactRoleSiteID IS NULL"; } gridElem.OnExternalDataBound += gridElem_OnExternalDataBound; gridElem.Pager.DefaultPageSize = 10; // Display 'Reset' button when 'none' role is allowed if (ValidationHelper.GetBoolean(Parameters["allownone"], false)) { btnReset.Visible = true; btnReset.Click += btn_Click; btnReset.CommandArgument = "0"; } }
/// <summary> /// Adds contact under account. /// </summary> private bool AddContactToAccount() { // Get dataset of contacts string where = "ContactLastName LIKE N'My New Contact%'"; var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(1); // Get dataset of accounts var accounts = AccountInfoProvider.GetAccounts().WhereEquals("AccountName", "My New Account"); // Get the role ContactRoleInfo role = ContactRoleInfoProvider.GetContactRoleInfo("MyNewRole", SiteContext.CurrentSiteName); if (!DataHelper.DataSourceIsEmpty(contacts) && (accounts.Any()) && (role != null)) { // Get the contact from dataset ContactInfo contact = contacts.First<ContactInfo>(); // Get the account from dataset AccountInfo account = accounts.First(); // Create new account - contact relationship AccountContactInfo accountContact = new AccountContactInfo() { AccountID = account.AccountID, ContactID = contact.ContactID, ContactRoleID = role.ContactRoleID }; // And save it AccountContactInfoProvider.SetAccountContactInfo(accountContact); return true; } return false; }
/// <summary> /// Reloads control. /// </summary> public void Reload() { // Load controls with data if (ai != null) { SiteID = ai.AccountSiteID; // Load values from DB if (!RequestHelper.IsPostBack()) { txtName.Text = ai.AccountName; accountStatus.Value = ai.AccountStatusID; parentAccount.Value = ai.AccountSubsidiaryOfID; accountOwner.Value = ai.AccountOwnerUserID; txtAddress1.Text = ai.AccountAddress1; txtAddress2.Text = ai.AccountAddress2; txtCity.Text = ai.AccountCity; txtZip.Text = ai.AccountZIP; countrySelector.CountryID = ai.AccountCountryID; countrySelector.StateID = ai.AccountStateID; txtPhone.Text = ai.AccountPhone; txtFax.Text = ai.AccountFax; emailInput.Value = ai.AccountEmail; txtURL.Text = ai.AccountWebSite; htmlNotes.Value = ai.AccountNotes; primaryContact.Value = ai.AccountPrimaryContactID; secondaryContact.Value = ai.AccountSecondaryContactID; // Get primary contact role AccountContactInfo aci = null; if (ai.AccountPrimaryContactID > 0) { aci = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, ai.AccountPrimaryContactID); if (aci != null) { contactRolePrimary.Value = aci.ContactRoleID; } } // Get secondary contact role if (ai.AccountSecondaryContactID > 0) { aci = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, ai.AccountSecondaryContactID); if (aci != null) { contactRoleSecondary.Value = aci.ContactRoleID; } } } // Setup selectors parentAccount.WhereCondition = "(AccountID NOT IN (SELECT * FROM Func_OM_Account_GetSubsidiaries(" + ai.AccountID + ", 1)) AND AccountMergedWithAccountID IS NULL)"; primaryContact.WhereCondition = "(ContactID IN (SELECT ContactID FROM OM_AccountContact WHERE AccountID = " + ai.AccountID + "))"; secondaryContact.WhereCondition = "(ContactID IN (SELECT ContactID FROM OM_AccountContact WHERE AccountID = " + ai.AccountID + "))"; // Reload controls parentAccount.ReloadData(); primaryContact.ReloadData(); secondaryContact.ReloadData(); accountOwner.ReloadData(); contactRolePrimary.ReloadData(); contactRoleSecondary.ReloadData(); accountStatus.ReloadData(); } }