Beispiel #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);
        }
    }