Exemple #1
0
    /// <summary>
    /// Handles import button click.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Event arguments</param>
    protected void btnImport_Click(object sender, EventArgs e)
    {
        // Check 'Manage subscribers' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "managesubscribers"))
        {
            RedirectToCMSDeskAccessDenied("cms.newsletter", "managesubscribers");
        }

        // Get selected newsletters
        List <int> newsletterIds = new List <int>();
        string     values        = ValidationHelper.GetString(usNewsletters.Value, null);

        if (!String.IsNullOrEmpty(values))
        {
            string[] newItems = values.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                foreach (string item in newItems)
                {
                    newsletterIds.Add(ValidationHelper.GetInteger(item, 0));
                }
            }
        }

        // Import subscribers
        try
        {
            if (CMSContext.CurrentSite != null)
            {
                int           siteId = CMSContext.CurrentSiteID;
                List <string> errors = new List <string>();

                // Add subscribers to site and subscribe them to selected newsletters
                if (radSubscribe.Checked)
                {
                    errors = SubscriberInfoProvider.ImportSubscribersToSite(txtImportSub.Text, newsletterIds, siteId, true, chkSendConfirmation.Checked, chkDoNotSubscribe.Checked, chkRequireOptIn.Checked);
                    if (errors.Count == 0)
                    {
                        ShowInformation(GetString("Subscriber_Import.SubscribersImported"));
                    }
                }
                // Unsubscribe inserted subscribers from selected newsletters
                else if (radUnsubscribe.Checked)
                {
                    errors = SubscriberInfoProvider.UnsubscribeFromNewsletters(txtImportSub.Text, newsletterIds, siteId, chkSendConfirmation.Checked);
                    if (errors.Count == 0)
                    {
                        ShowInformation(GetString("Subscriber_Import.SubscribersUnsubscribed"));
                    }
                }
                // Delete inserted subscribers
                else if (radDelete.Checked)
                {
                    errors = SubscriberInfoProvider.DeleteSubscribers(txtImportSub.Text, siteId);
                    if (errors.Count == 0)
                    {
                        ShowInformation(GetString("Subscriber_Import.SubscribersDeleted"));
                    }
                }

                if (errors.Count > 0)
                {
                    ShowError(GetString("general.erroroccurred"), CreateErrorString(errors), null);
                }
            }
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }
Exemple #2
0
    /// <summary>
    /// Handles import button click.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Event arguments</param>
    protected void btnImport_Click(object sender, EventArgs e)
    {
        // Check 'Manage subscribers' permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.newsletter", "managesubscribers"))
        {
            RedirectToAccessDenied("cms.newsletter", "managesubscribers");
        }

        if (String.IsNullOrEmpty(txtImportSub.Text.Trim()))
        {
            ShowError(GetString("Subscriber_Import.nosubscribers"));
            return;
        }

        // Import subscribers
        try
        {
            // Get selected newsletters
            int        siteId        = SiteContext.CurrentSiteID;
            List <int> newsletterIds = new List <int>();
            string     values        = ValidationHelper.GetString(usNewsletters.Value, null);
            if (!String.IsNullOrEmpty(values))
            {
                string[] newItems = values.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in newItems)
                {
                    var newsletter = NewsletterInfoProvider.GetNewsletterInfo(item.ToInteger(0));

                    if ((newsletter == null) || (newsletter.NewsletterSiteID != siteId))
                    {
                        continue;
                    }

                    newsletterIds.Add(newsletter.NewsletterID);
                }
            }

            AsyncErrors = null;

            // Add subscribers to site and subscribe them to selected newsletters
            if (radSubscribe.Checked)
            {
                var parameter = new object[] { txtImportSub.Text, newsletterIds, siteId, true, chkSendConfirmation.Checked, chkDoNotSubscribe.Checked, chkRequireOptIn.Checked, ctlAsyncLog.ProcessGUID, AsyncErrors };
                RunAsync(p => SubscriberImporter.ImportSubscribersToSite(parameter));

                CurrentInfo           = GetString("Subscriber_Import.SubscribersImported");
                ctlAsyncLog.TitleText = GetString("newsletters.importingsubscribers");
            }
            // Unsubscribe inserted subscribers from selected newsletters
            else if (radUnsubscribe.Checked)
            {
                if (newsletterIds.Count > 0)
                {
                    var parameter = new object[] { txtImportSub.Text, newsletterIds, siteId, chkSendConfirmation.Checked, ctlAsyncLog.ProcessGUID, AsyncErrors };
                    RunAsync(p => SubscriberInfoProvider.RemoveSubscriptions(parameter));

                    CurrentInfo           = GetString("Subscriber_Import.SubscribersUnsubscribed");
                    ctlAsyncLog.TitleText = GetString("newsletters.unsubscribing");
                }
                else
                {
                    ShowError(GetString("ImportSubscribers.NoNewslettersSelected"));
                }
            }
            // Delete inserted subscribers
            else if (radDelete.Checked)
            {
                var parameter = new object[] { txtImportSub.Text, siteId, ctlAsyncLog.ProcessGUID, AsyncErrors };
                RunAsync(p => SubscriberInfoProvider.DeleteSubscribers(parameter));

                CurrentInfo           = GetString("Subscriber_Import.SubscribersDeleted");
                ctlAsyncLog.TitleText = GetString("newsletters.deleting");
            }
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }