/// <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> /// Contact group items selected event handler. /// </summary> protected void selector_OnItemsSelected(object sender, EventArgs e) { // Check permissions CheckAuthorization(); if (cgSelector == null) { return; } int groupID = 0; string[] newItems = null; Subscriber sb = null; int siteId = CMSContext.CurrentSiteID; string cgType = "om.contactgroup"; // 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) { groupID = ValidationHelper.GetInteger(item, 0); // Get subscriber sb = SubscriberProvider.GetSubscriber(cgType, groupID, siteId); if (sb == null) { // Get contact group display name string cgName = ModuleCommands.OnlineMarketingGetContactGroupName(groupID); if (string.IsNullOrEmpty(cgName)) { break; } // Check limited number of subscribers if (!SubscriberProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Subscribers, VersionActionEnum.Insert)) { lblError.Text = GetString("licenselimitations.subscribers.errormultiple"); lblError.Visible = true; break; } // Create new subscriber of contact group type sb = new Subscriber(); 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; SubscriberProvider.SetSubscriber(sb); } // If subscriber exists and is not subscribed, subscribe him if ((sb != null) && (!SubscriberProvider.IsSubscribed(sb.SubscriberID, newsletterId))) { try { SubscriberProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, chkSendConfirmation.Checked, false); } catch { } } } } cgSelector.Value = null; UniGridSubscribers.ReloadData(); pnlUpdate.Update(); }