/// <summary> /// Creates a subscriber object. If the subscriber with the given e-mail address already exists, returns the existing subscriber. /// </summary> /// <param name="email">Subscriber's e-mail address</param> /// <returns>Returns new subscriber object. If the subscriber with the given email already exists, returns the existing subscriber.</returns> private SubscriberInfo SaveSubscriber(string email) { // Gets information about subscriber based on email address and current site SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(email, SiteId); if (subscriber == null) { // Creates new subscriber subscriber = new SubscriberInfo { SubscriberEmail = email, SubscriberSiteID = SiteId }; // Checks subscriber license limitation if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { CoreServices.EventLog.LogEvent("W", "Newsletters", "SaveSubscriber", "Subscriber could not be added due to license limitations."); return(null); } // Saves subscriber info SubscriberInfoProvider.SetSubscriberInfo(subscriber); } return(subscriber); }
protected void OnBeforeSave(object sender, EventArgs e) { // Check license if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { NewForm.StopProcessing = true; ShowError(GetString("LicenseVersionCheck.Subscribers")); } // Set SiteID NewForm.Data.SetValue("SubscriberSiteID", SiteContext.CurrentSiteID); string firstName = ValidationHelper.GetString(NewForm.GetFieldValue("SubscriberFirstName"), string.Empty); string lastName = ValidationHelper.GetString(NewForm.GetFieldValue("SubscriberLastName"), string.Empty); // Set full name NewForm.Data.SetValue("SubscriberFullName", string.Concat(firstName, " ", lastName)); string email = ValidationHelper.GetString(NewForm.GetFieldValue("SubscriberEmail"), string.Empty); // Check email if (email == string.Empty) { NewForm.StopProcessing = true; ShowError(GetString("Subscriber_Edit.ErrorEmptyEmail")); } else if (SubscriberInfoProvider.EmailExists(email)) { NewForm.StopProcessing = true; ShowError(GetString("Subscriber_Edit.EmailAlreadyExists")); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check "Manage subscribers" permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "managesubscribers")) { RedirectToCMSDeskAccessDenied("cms.newsletter", "managesubscribers"); } string email = txtSubscriberEmail.Text.Trim(); // Check entered values string errorMessage = new Validator().NotEmpty(email, GetString("Subscriber_Edit.ErrorEmptyEmail")) .IsEmail(email, GetString("NewsletterSubscription.ErrorInvalidEmail")) .Result; if (string.IsNullOrEmpty(errorMessage)) { if (!SubscriberInfoProvider.EmailExists(email)) { // Create new subscriber info and set values SubscriberInfo subscriberObj = new SubscriberInfo(); subscriberObj.SubscriberID = 0; subscriberObj.SubscriberLastName = txtSubscriberLastName.Text.Trim(); subscriberObj.SubscriberEmail = email; subscriberObj.SubscriberFirstName = txtSubscriberFirstName.Text.Trim(); subscriberObj.SubscriberFullName = (subscriberObj.SubscriberFirstName + " " + subscriberObj.SubscriberLastName).Trim(); subscriberObj.SubscriberSiteID = CMSContext.CurrentSiteID; subscriberObj.SubscriberGUID = Guid.NewGuid(); if (SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert)) { // Save subscriber to DB SubscriberInfoProvider.SetSubscriberInfo(subscriberObj); // Redirect to edit page URLHelper.Redirect("Subscriber_Frameset.aspx?subscriberid=" + Convert.ToString(subscriberObj.SubscriberID) + "&saved=1"); } else { ShowError(GetString("LicenseVersionCheck.Subscribers")); } } else { ShowError(GetString("Subscriber_Edit.EmailAlreadyExists")); } } else { ShowError(errorMessage); } }
/// <summary> /// Saves subscriber. /// </summary> /// <param name="email">Subscriber's e-mail address</param> /// <param name="errorMessage">Error message used when save failed</param> /// <returns>Subscriber info object</returns> private SubscriberInfo SaveSubscriber(string email, out string errorMessage) { errorMessage = string.Empty; // Checks whether this IP address is banned or not if (!BannedIPInfoProvider.IsAllowed(mSiteName, BanControlEnum.AllNonComplete)) { errorMessage = ResHelper.GetString("General.BannedIP"); return(null); } // Gets information about subscriber based on email address and current site SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(email, SiteId); if (subscriber == null) { // Creates new subscriber subscriber = new SubscriberInfo { SubscriberEmail = email, SubscriberSiteID = SiteId }; // Checks subscriber limits if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { errorMessage = ResHelper.GetString("LicenseVersionCheck.Subscribers"); return(null); } // Saves subscriber info SubscriberInfoProvider.SetSubscriberInfo(subscriber); } // Returns subscriber info object return(subscriber); }
/// <summary> /// Save subscriber. /// </summary> /// <returns>Subscriver info object</returns> private SubscriberInfo SaveSubscriber() { // Check if a subscriber exists first SubscriberInfo sb = null; if (AllowUserSubscribers && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated()) { sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, MembershipContext.AuthenticatedUser.UserID, SiteContext.CurrentSiteID); } else { sb = SubscriberInfoProvider.GetSubscriberInfo(txtEmail.Text, SiteContext.CurrentSiteID); } if ((sb == null) || ((chooseMode) && (sb != null))) { // Create subscriber if (sb == null) { sb = new SubscriberInfo(); } // Handle authenticated user if (AllowUserSubscribers && (MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated()) { // Get user info and copy first name, last name or full name to new subscriber UserInfo ui = UserInfoProvider.GetUserInfo(MembershipContext.AuthenticatedUser.UserID); if (ui != null) { if (!DataHelper.IsEmpty(ui.FirstName) && !DataHelper.IsEmpty(ui.LastName)) { sb.SubscriberFirstName = ui.FirstName; sb.SubscriberLastName = ui.LastName; } else { sb.SubscriberFirstName = ui.FullName; } // Full name consists of "user " and user full name sb.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName); } else { return(null); } sb.SubscriberType = UserInfo.OBJECT_TYPE; sb.SubscriberRelatedID = MembershipContext.AuthenticatedUser.UserID; } // Work with non-authenticated user else { sb.SubscriberEmail = txtEmail.Text.Trim(); // First name if (DisplayFirstName) { sb.SubscriberFirstName = txtFirstName.Text; } else { sb.SubscriberFirstName = string.Empty; } // Last name if (DisplayLastName) { sb.SubscriberLastName = txtLastName.Text; } else { sb.SubscriberLastName = string.Empty; } // Full name sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim(); } // Set site ID sb.SubscriberSiteID = SiteContext.CurrentSiteID; // Check subscriber limits if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { lblError.Visible = true; lblError.Text = GetString("LicenseVersionCheck.Subscribers"); return(null); } // Save subscriber info SubscriberInfoProvider.SetSubscriberInfo(sb); } if (sb != null) { // Create membership between current contact and subscriber ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID()); } // Hide all visibleLastName = false; visibleFirstName = false; visibleEmail = false; pnlButtonSubmit.Visible = false; pnlImageSubmit.Visible = false; plcNwsList.Visible = false; // Clear the form txtEmail.Text = string.Empty; txtFirstName.Text = string.Empty; txtLastName.Text = string.Empty; // Return subscriber info object return(sb); }
/// <summary> /// Save subscriber. /// </summary> /// <returns>Subscriber info object</returns> private SubscriberInfo SaveSubscriber() { string emailValue = null; int currentSiteId = SiteContext.CurrentSiteID; // Check if a subscriber exists first SubscriberInfo sb = null; if (AllowUserSubscribers && isAuthenticated) { // Try to get user subscriber sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, CurrentUser.UserID, currentSiteId); } else { EditingFormControl txtEmail = formElem.FieldEditingControls["SubscriberEmail"] as EditingFormControl; if (txtEmail != null) { emailValue = ValidationHelper.GetString(txtEmail.Value, String.Empty); } if (!string.IsNullOrEmpty(emailValue)) { // Try to get subscriber by email address sb = SubscriberInfoProvider.GetSubscriberInfo(emailValue, currentSiteId); } } if ((sb == null) || (chooseMode)) { // Create subscriber if (sb == null) { if (formElem.Visible) { int formSiteId = formElem.Data.GetValue("SubscriberSiteID").ToInteger(0); if (formSiteId == 0) { // Specify SiteID for the new subscriber formElem.Data.SetValue("SubscriberSiteID", currentSiteId); } // Save form with new subscriber data if (!formElem.Save()) { return(null); } // Get subscriber info from form sb = (SubscriberInfo)formElem.Info; } else { sb = new SubscriberInfo(); } } // Handle authenticated user if (AllowUserSubscribers && isAuthenticated) { // Get user info and copy first name, last name or full name to new subscriber // if these properties were not set UserInfo ui = UserInfoProvider.GetUserInfo(CurrentUser.UserID); if (ui != null) { if (!DataHelper.IsEmpty(ui.FirstName) && !DataHelper.IsEmpty(ui.LastName)) { if (string.IsNullOrEmpty(sb.SubscriberFirstName)) { sb.SubscriberFirstName = ui.FirstName; } if (string.IsNullOrEmpty(sb.SubscriberLastName)) { sb.SubscriberLastName = ui.LastName; } } else { if (string.IsNullOrEmpty(sb.SubscriberFirstName)) { sb.SubscriberFirstName = ui.FullName; } } // Full name consists of "user " and user full name sb.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName); if (!string.IsNullOrEmpty(sb.SubscriberEmail) && string.IsNullOrEmpty(ui.Email)) { // Update user email if it was not set ui.Email = sb.SubscriberEmail; UserInfoProvider.SetUserInfo(ui); // Reset email for user subscriber sb.SubscriberEmail = null; } } else { return(null); } sb.SubscriberType = UserInfo.OBJECT_TYPE; sb.SubscriberRelatedID = ui.UserID; } // Work with non-authenticated user else { if (string.IsNullOrEmpty(sb.SubscriberFullName)) { // Fill full name if it was not set via the form sb.SubscriberFullName = (sb.SubscriberFirstName + " " + sb.SubscriberLastName).Trim(); } } // Set site ID sb.SubscriberSiteID = SiteContext.CurrentSiteID; // Insert or update subscriber info SubscriberInfoProvider.SetSubscriberInfo(sb); // Check subscriber limits if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { // Remove created subscriber and display error message SubscriberInfoProvider.DeleteSubscriberInfo(sb); lblError.Visible = true; lblError.Text = GetString("LicenseVersionCheck.Subscribers"); return(null); } } if (sb != null) { // Create membership between current contact and subscriber ModuleCommands.OnlineMarketingCreateRelation(sb.SubscriberID, MembershipType.NEWSLETTER_SUBSCRIBER, ModuleCommands.OnlineMarketingGetCurrentContactID()); } // Return subscriber info object return(sb); }
/// <summary> /// Persona items selected event handler. /// </summary> protected void PersonaSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); if (personaSelector == null) { return; } int siteId = SiteContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(personaSelector.Value, null); // Get added items string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Personas, ObjectActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } // Get persona ID int personaID = ValidationHelper.GetInteger(item, 0); // Try to get subscriber SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.PERSONA, personaID, siteId); if (subscriber == null) { // Get persona display name var persona = BaseAbstractInfoProvider.GetInfoById(PredefinedObjectType.PERSONA, personaID); string personaName = ValidationHelper.GetString(persona.GetValue("PersonaDisplayName"), string.Empty); if (string.IsNullOrEmpty(personaName)) { continue; } // Create new subscriber of persona type subscriber = new SubscriberInfo(); subscriber.SubscriberFirstName = personaName; // Full name consists of "persona" and display name subscriber.SubscriberFullName = new SubscriberFullNameFormater().GetPersonaSubscriberName(personaName); subscriber.SubscriberSiteID = siteId; subscriber.SubscriberType = PredefinedObjectType.PERSONA; subscriber.SubscriberRelatedID = personaID; CheckPermissionsForSubscriber(subscriber); SubscriberInfoProvider.SetSubscriberInfo(subscriber); } if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID)) { mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings() { SendConfirmationEmail = chkSendConfirmation.Checked, RequireOptIn = false, RemoveAlsoUnsubscriptionFromAllNewsletters = false, }); } } personaSelector.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Contact items selected event handler. /// </summary> protected void ContactSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); if (cSelector == null) { return; } int siteId = SiteContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(cSelector.Value, null); // Get added items string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } // Get contact ID int contactID = ValidationHelper.GetInteger(item, 0); // Try to get subscriber SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.CONTACT, contactID, siteId); if (subscriber == null) { // Get contact's info DataSet contactData = ModuleCommands.OnlineMarketingGetContactForNewsletters(contactID, "ContactFirstName,ContactMiddleName,ContactLastName,ContactEmail"); if (DataHelper.DataSourceIsEmpty(contactData)) { continue; } string firstName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactFirstName"], string.Empty); string lastName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactLastName"], string.Empty); string middleName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactMiddleName"], string.Empty); string email = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactEmail"], string.Empty); // Create new subscriber of contact type subscriber = new SubscriberInfo(); subscriber.SubscriberFirstName = firstName; subscriber.SubscriberLastName = lastName; subscriber.SubscriberEmail = email; subscriber.SubscriberFullName = new SubscriberFullNameFormater().GetContactSubscriberName(firstName, middleName, lastName); subscriber.SubscriberSiteID = siteId; subscriber.SubscriberType = PredefinedObjectType.CONTACT; subscriber.SubscriberRelatedID = contactID; CheckPermissionsForSubscriber(subscriber); SubscriberInfoProvider.SetSubscriberInfo(subscriber); } if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID)) { mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings() { SendConfirmationEmail = chkSendConfirmation.Checked, RequireOptIn = chkRequireOptIn.Checked, RemoveAlsoUnsubscriptionFromAllNewsletters = false, }); } } cSelector.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Contact group items selected event handler. /// </summary> protected void CGSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); if (cgSelector == null) { return; } int siteId = SiteContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(cgSelector.Value, null); // Get added items string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } // Get group ID int groupID = ValidationHelper.GetInteger(item, 0); // Try to get subscriber SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(PredefinedObjectType.CONTACTGROUP, groupID, siteId); if (subscriber == null) { // Get contact group display name string cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID); if (string.IsNullOrEmpty(cgName)) { continue; } // Create new subscriber of contact group type subscriber = new SubscriberInfo(); subscriber.SubscriberFirstName = cgName; // Full name consists of "contact group " and display name subscriber.SubscriberFullName = new SubscriberFullNameFormater().GetContactGroupSubscriberName(cgName); subscriber.SubscriberSiteID = siteId; subscriber.SubscriberType = PredefinedObjectType.CONTACTGROUP; subscriber.SubscriberRelatedID = groupID; CheckPermissionsForSubscriber(subscriber); SubscriberInfoProvider.SetSubscriberInfo(subscriber); } if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID)) { mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings() { SendConfirmationEmail = chkSendConfirmation.Checked, RequireOptIn = false, RemoveAlsoUnsubscriptionFromAllNewsletters = false, }); } } cgSelector.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// User control items changed event. /// </summary> protected void UserSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); int siteId = SiteContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(selectUser.Value, null); string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } int userID = ValidationHelper.GetInteger(item, 0); // Get subscriber SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, userID, siteId); if (subscriber == null) { // Get user info UserInfo ui = UserInfoProvider.GetUserInfo(userID); if (ui == null) { continue; } // Create new subscriber of user type subscriber = new SubscriberInfo(); subscriber.SubscriberFirstName = ui.FullName; subscriber.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName); subscriber.SubscriberSiteID = siteId; subscriber.SubscriberType = UserInfo.OBJECT_TYPE; subscriber.SubscriberRelatedID = userID; CheckPermissionsForSubscriber(subscriber); SubscriberInfoProvider.SetSubscriberInfo(subscriber); } if (!mSubscriptionService.IsSubscribed(subscriber.SubscriberID, mNewsletter.NewsletterID)) { mSubscriptionService.Subscribe(subscriber.SubscriberID, mNewsletter.NewsletterID, new SubscribeSettings() { SendConfirmationEmail = chkSendConfirmation.Checked, RequireOptIn = chkRequireOptIn.Checked, RemoveAlsoUnsubscriptionFromAllNewsletters = false, }); } } selectUser.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// User control items changed event. /// </summary> protected void UserSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); int siteId = SiteContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(selectUser.Value, null); string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Subscribers, ObjectActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } int userID = ValidationHelper.GetInteger(item, 0); // Get subscriber SubscriberInfo sb = SubscriberInfoProvider.GetSubscriberInfo(UserInfo.OBJECT_TYPE, userID, siteId); if (sb == null) { // Get user info UserInfo ui = UserInfoProvider.GetUserInfo(userID); if (ui == null) { continue; } // Create new subscriber of user type sb = new SubscriberInfo(); sb.SubscriberFirstName = ui.FullName; sb.SubscriberFullName = new SubscriberFullNameFormater().GetUserSubscriberName(ui.FullName); sb.SubscriberSiteID = siteId; sb.SubscriberType = UserInfo.OBJECT_TYPE; sb.SubscriberRelatedID = userID; CheckPermissionsForSubscriber(sb); SubscriberInfoProvider.SetSubscriberInfo(sb); } // If subscriber exists and is not subscribed, subscribe him if (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, mNewsletter.NewsletterID)) { try { SubscriberInfoProvider.Subscribe(sb.SubscriberID, mNewsletter.NewsletterID, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked); } catch (InvalidOperationException ex) { ShowError(ex.Message); } } } selectUser.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Contact items selected event handler. /// </summary> protected void ContactSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); if (cSelector == null) { return; } int contactID = 0; string[] newItems = null; SubscriberInfo sb = null; int siteId = CMSContext.CurrentSiteID; string cType = PredefinedObjectType.CONTACT; DataSet contactData = null; // Get new items from selector string newValues = ValidationHelper.GetString(cSelector.Value, null); // Get added items newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } // Get contact ID contactID = ValidationHelper.GetInteger(item, 0); // Try to get subscriber sb = SubscriberInfoProvider.GetSubscriberInfo(cType, contactID, siteId); if (sb == null) { // Get contact's info contactData = ModuleCommands.OnlineMarketingGetContactForNewsletters(contactID, "ContactFirstName,ContactMiddleName,ContactLastName"); if (DataHelper.DataSourceIsEmpty(contactData)) { continue; } string firstName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactFirstName"], string.Empty); string lastName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactLastName"], string.Empty); string middleName = ValidationHelper.GetString(contactData.Tables[0].Rows[0]["ContactMiddleName"], string.Empty); // Create new subscriber of contact type sb = new SubscriberInfo(); sb.SubscriberFirstName = firstName; sb.SubscriberLastName = lastName; sb.SubscriberFullName = string.Format("Contact '{0}{1}{2}'", string.IsNullOrEmpty(firstName) ? string.Empty : firstName + " ", string.IsNullOrEmpty(middleName) ? string.Empty : middleName + " ", lastName); sb.SubscriberSiteID = siteId; sb.SubscriberType = cType; sb.SubscriberRelatedID = contactID; SubscriberInfoProvider.SetSubscriberInfo(sb); } // If subscriber exists and is not subscribed, subscribe him if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))) { try { SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked); } catch { } } } } cSelector.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Contact group items selected event handler. /// </summary> protected void CGSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); if (cgSelector == null) { return; } int groupID = 0; string[] newItems = null; SubscriberInfo sb = null; int siteId = CMSContext.CurrentSiteID; string cgType = "om.contactgroup"; string cgName = null; // Get new items from selector string newValues = ValidationHelper.GetString(cgSelector.Value, null); // Get added items newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } // Get group ID groupID = ValidationHelper.GetInteger(item, 0); // Try to get subscriber sb = SubscriberInfoProvider.GetSubscriberInfo(cgType, groupID, siteId); if (sb == null) { // Get contact group display name cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID); if (string.IsNullOrEmpty(cgName)) { continue; } // Create new subscriber of contact group type sb = new SubscriberInfo(); sb.SubscriberFirstName = cgName; // Full name consists of "contact group " and display name sb.SubscriberFullName = string.Concat("Contact group '", cgName, "'"); sb.SubscriberSiteID = siteId; sb.SubscriberType = cgType; sb.SubscriberRelatedID = groupID; SubscriberInfoProvider.SetSubscriberInfo(sb); } // If subscriber exists and is not subscribed, subscribe him if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))) { try { SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false); } catch { } } } } cgSelector.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// User control items changed event. /// </summary> protected void UserSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); int userID = 0; string[] newItems = null; SubscriberInfo sb = null; UserInfo ui = null; int siteId = CMSContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(selectUser.Value, null); newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } userID = ValidationHelper.GetInteger(item, 0); // Get subscriber sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.USER, userID, siteId); if (sb == null) { // Get user info ui = UserInfoProvider.GetUserInfo(userID); if (ui == null) { continue; } // Create new subscriber of user type sb = new SubscriberInfo(); sb.SubscriberFirstName = ui.FullName; sb.SubscriberFullName = "User '" + ui.FullName + "'"; sb.SubscriberSiteID = siteId; sb.SubscriberType = SiteObjectType.USER; sb.SubscriberRelatedID = userID; SubscriberInfoProvider.SetSubscriberInfo(sb); } // If subscriber exists and is not subscribed, subscribe him if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))) { try { SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, chkRequireOptIn.Checked); } catch { } } } } selectUser.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Roles control items changed event. /// </summary> protected void RolesSelector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); int roleID = 0; string[] newItems = null; SubscriberInfo sb = null; RoleInfo ri = null; int siteId = CMSContext.CurrentSiteID; // Get new items from selector string newValues = ValidationHelper.GetString(selectRole.Value, null); // Get added items newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { foreach (string item in newItems) { // Check limited number of subscribers if (!SubscriberInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert)) { ShowError(GetString("licenselimitations.subscribers.errormultiple")); break; } roleID = ValidationHelper.GetInteger(item, 0); // Get subscriber sb = SubscriberInfoProvider.GetSubscriberInfo(SiteObjectType.ROLE, roleID, siteId); if (sb == null) { // Get role info and copy display name to new subscriber ri = RoleInfoProvider.GetRoleInfo(roleID); if ((ri == null) || (ri.SiteID != siteId)) { continue; } // Create new subscriber of role type sb = new SubscriberInfo(); sb.SubscriberFirstName = ri.DisplayName; // Full name consists of "role " and role display name sb.SubscriberFullName = string.Concat("Role '", ri.DisplayName, "'"); sb.SubscriberSiteID = siteId; sb.SubscriberType = SiteObjectType.ROLE; sb.SubscriberRelatedID = roleID; SubscriberInfoProvider.SetSubscriberInfo(sb); } // If subscriber exists and is not subscribed, subscribe him if ((sb != null) && (!SubscriberInfoProvider.IsSubscribed(sb.SubscriberID, newsletterId))) { try { SubscriberInfoProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false); } catch { } } } } selectRole.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }