public override bool LoadData(ActivityInfo ai)
    {
        if ((ai == null) || (ai.ActivityType != PredefinedActivityType.NEWSLETTER_CLICKTHROUGH))
        {
            return(false);
        }

        // Get newsletter name
        int            newsletterId   = ai.ActivityItemID;
        NewsletterInfo newsletterInfo = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);

        if (newsletterInfo != null)
        {
            ucDetails.AddRow("om.activitydetails.newsletter", newsletterInfo.NewsletterDisplayName);
        }

        // Get issue subject
        int       issueId   = ai.ActivityItemDetailID;
        IssueInfo issueInfo = IssueInfoProvider.GetIssueInfo(issueId);

        if (issueInfo != null)
        {
            ucDetails.AddRow("om.activitydetails.newsletterissue", issueInfo.IssueDisplayName);
        }

        string targetLink = ai.ActivityURL;

        ucDetails.AddRow("om.activitydetails.newstargetlink", GetLink(targetLink, targetLink), false);

        return(ucDetails.IsDataLoaded);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get issue object
        int       issueId = QueryHelper.GetInteger("issueid", 0);
        IssueInfo issue   = IssueInfoProvider.GetIssueInfo(issueId);

        if (issue != null)
        {
            // Get newsletter object
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(issue.IssueNewsletterID);
            if (news != null)
            {
                if (news.NewsletterType == NewsletterType.Dynamic)
                {
                    // Only send page is allowed for dynamic newsletters
                    issueContentUrl = "Newsletter_Issue_Send.aspx?issueid=" + issueId.ToString();
                }
                else
                {
                    issueContentUrl = "Newsletter_Issue_Edit.aspx?issueid=" + issueId.ToString();
                }
            }
        }

        if (string.IsNullOrEmpty(issueContentUrl))
        {
            issueContentUrl = "Newsletter_Issue_Edit.aspx";
        }
    }
Exemple #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Reset master page content CSS class
        CurrentMaster.PanelContent.CssClass = string.Empty;

        // Get edited issue object and check its existence
        IssueInfo issue = (IssueInfo)EditedObject;

        EditedObject = issue;

        // Get newsletter and check its existence
        newsletter = NewsletterInfoProvider.GetNewsletterInfo(issue.IssueNewsletterID);
        if ((newsletter != null) && (newsletter.NewsletterType == NewsletterType.Dynamic))
        {
            ShowError(GetString("Newsletter_Issue_Edit.CannotBeEdited"));
            editElem.StopProcessing = true;
            editElem.Visible        = false;
            return;
        }

        // Get variant issue ID if A/B testing is ON
        int issueId = InitVariantSlider(issue.IssueID);

        // Initialize edit control
        editElem.IssueID      = issueId;
        editElem.NewsletterID = issue.IssueNewsletterID;
        editElem.IsDialogMode = false;

        InitHeaderActions(issueId);
    }
    /// <summary>
    /// Logs activity for unsubscribing.
    /// </summary>
    /// <param name="sb">Subscriber (optional - can be null if subscriber ID is used)</param>
    /// <param name="subscriberId">Subscriber ID (optional - can be zero if subscriber object is used)</param>
    /// <param name="newsletterId">Newsletter ID</param>
    /// <param name="issueId">Issue ID</param>
    /// <param name="contactId">Contact ID is present if the mail is sent to a contact or a contact group</param>
    private void LogActivity(SubscriberInfo sb, int subscriberId, int newsletterId, int issueId, int contactId)
    {
        bool isFromContactGroup = !string.IsNullOrEmpty(sb.SubscriberType) && sb.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true);

        if (contactId <= 0)
        {
            contactId = ActivityTrackingHelper.GetContactID(sb);
        }

        if (sb == null)
        {
            sb = SubscriberInfoProvider.GetSubscriberInfo(subscriberId);
        }

        if (contactId > 0)
        {
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);

            Activity activity = new ActivityNewsletterUnsubscribing(sb, news, CMSContext.ActivityEnvironmentVariables);
            if (activity.Data != null)
            {
                activity.Data.ContactID    = contactId;
                activity.Data.ItemDetailID = issueId;
                activity.Data.Value        = isFromContactGroup ? "contactgroup(" + sb.SubscriberRelatedID + ")" : null;
                activity.Log();
            }
        }
    }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check read permission for newsletters
        if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Newsletter", "Read"))
        {
            IssueInfo iss     = null;
            int       issueId = QueryHelper.GetInteger("IssueId", 0);
            if (issueId > 0)
            {
                // Get newsletter issue by ID
                iss = IssueInfoProvider.GetIssueInfo(issueId);
            }
            else
            {
                // Get newsletter issue by GUID and site ID
                Guid issueGuid = QueryHelper.GetGuid("IssueGUID", Guid.Empty);
                iss = IssueInfoProvider.GetIssueInfo(issueGuid, SiteContext.CurrentSiteID);
            }

            if ((iss != null) && (iss.IssueSiteID == SiteContext.CurrentSiteID))
            {
                // Get newsletter
                NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(iss.IssueNewsletterID);

                Response.Clear();
                Response.Write(IssueInfoProvider.GetEmailBody(iss, news, null, null, false, SiteContext.CurrentSiteName, null, null, null));
                Response.Flush();

                RequestHelper.EndResponse();
            }
        }
    }
        public ActionResult SubscribeAuthenticated()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Show());
            }

            var user       = UserManager.FindByName(User.Identity.Name);
            var contact    = mContactProvider.GetContactForSubscribing(user.Email, user.FirstName, user.LastName);
            var newsletter = NewsletterInfoProvider.GetNewsletterInfo("DancingGoatMvcNewsletter", SiteContext.CurrentSiteID);

            string resultMessage;

            if (!mSubscriptionService.IsMarketable(contact, newsletter))
            {
                mSubscriptionService.Subscribe(contact, newsletter, NewsletterSubscriptionSettings);

                // The subscription service is configured to use double opt-in, but newsletter must allow for it
                resultMessage = ResHelper.GetString(newsletter.NewsletterEnableOptIn ? "DancingGoatMvc.News.ConfirmationSent" : "DancingGoatMvc.News.Subscribed");
            }
            else
            {
                resultMessage = ResHelper.GetString("DancingGoatMvc.News.AlreadySubscribed");
            }

            return(Content(resultMessage));
        }
    /// <summary>
    /// Logs activity for unsubscribing.
    /// </summary>
    /// <param name="subscriber">Subscriber</param>
    /// <param name="newsletterId">Newsletter ID</param>
    /// <param name="issueId">Issue ID</param>
    /// <param name="contactId">Contact ID is present if the mail is sent to a contact or a contact group</param>
    private void LogActivity(SubscriberInfo subscriber, int newsletterId, int issueId, int contactId)
    {
        if (subscriber == null)
        {
            throw new ArgumentNullException("subscriber");
        }
        if (contactId <= 0)
        {
            contactId = ActivityTrackingHelper.GetContactID(subscriber);
        }

        if (contactId > 0)
        {
            NewsletterInfo news = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);
            bool           isFromContactGroup = subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.CONTACTGROUP, true);
            bool           isFromPersona      = subscriber.SubscriberType.EqualsCSafe(PredefinedObjectType.PERSONA, true);
            Activity       activity           = new ActivityNewsletterUnsubscribing(subscriber, news, AnalyticsContext.ActivityEnvironmentVariables);
            if (activity.Data != null)
            {
                activity.Data.ContactID    = contactId;
                activity.Data.ItemDetailID = issueId;
                if (isFromContactGroup)
                {
                    activity.Data.Value = "contactgroup(" + subscriber.SubscriberRelatedID + ")";
                }
                else if (isFromPersona)
                {
                    activity.Data.Value = "persona(" + subscriber.SubscriberRelatedID + ")";
                }
                activity.Log();
            }
        }
    }
    public override bool LoadData(ActivityInfo ai)
    {
        if ((ai == null) || (ai.ActivityType != PredefinedActivityType.NEWSLETTER_UNSUBSCRIBING_FROM_ALL))
        {
            return(false);
        }

        // Get issue subject
        int issueId   = ai.ActivityItemID;
        var issueInfo = IssueInfoProvider.GetIssueInfo(issueId);

        if (issueInfo != null)
        {
            // Get newsletter name
            var newsletterInfo = NewsletterInfoProvider.GetNewsletterInfo(issueInfo.IssueNewsletterID);
            if (newsletterInfo != null)
            {
                ucDetails.AddRow("om.activitydetails.newsletter", newsletterInfo.NewsletterDisplayName);
            }

            var issueSubject = MacroSecurityProcessor.RemoveSecurityParameters(issueInfo.IssueSubject, true, null);
            ucDetails.AddRow("om.activitydetails.newsletterissue", issueSubject);
        }

        return(ucDetails.IsDataLoaded);
    }
        public ActionResult Subscribe(SubscribeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_Subscribe", model));
            }

            var newsletter = NewsletterInfoProvider.GetNewsletterInfo("DancingGoatMvcNewsletter", SiteContext.CurrentSiteID);
            var contact    = mContactProvider.GetContactForSubscribing(model.Email);

            string resultMessage;

            if (!mSubscriptionService.IsMarketable(contact, newsletter))
            {
                mSubscriptionService.Subscribe(contact, newsletter, NewsletterSubscriptionSettings);

                // The subscription service is configured to use double opt-in, but newsletter must allow for it
                resultMessage = ResHelper.GetString(newsletter.NewsletterEnableOptIn ? "DancingGoatMvc.News.ConfirmationSent" : "DancingGoatMvc.News.Subscribed");
            }
            else
            {
                resultMessage = ResHelper.GetString("DancingGoatMvc.News.AlreadySubscribed");
            }

            return(Content(resultMessage));
        }
    /// <summary>
    /// Deletes dynamic issue. Called when the "Delete issue" button is pressed.
    /// Expects the CreateDynamicIssue method to be run first.
    /// </summary>
    private bool DeleteDynamicIssue()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", CMSContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Prepare the parameters
            string where = "IssueNewsletterID = " + newsletter.NewsletterID;

            // Get the data
            DataSet issues = IssueInfoProvider.GetIssues(where, null);

            if (!DataHelper.DataSourceIsEmpty(issues))
            {
                // Create object from DataRow
                IssueInfo deleteIssue = new IssueInfo(issues.Tables[0].Rows[0]);

                // Delete the dynamic issue
                IssueInfoProvider.DeleteIssueInfo(deleteIssue);

                return(deleteIssue != null);
            }
        }
        return(false);
    }
    /// <summary>
    /// Gets and bulk updates dynamic issues. Called when the "Get and bulk update issues" button is pressed.
    /// Expects the CreateDynamicIssue method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateDynamicIssues()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", CMSContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Prepare the parameters
            string where = "IssueNewsletterID = " + newsletter.NewsletterID;

            // Get the data
            DataSet issues = IssueInfoProvider.GetIssues(where, null);
            if (!DataHelper.DataSourceIsEmpty(issues))
            {
                // Loop through the individual items
                foreach (DataRow issueDr in issues.Tables[0].Rows)
                {
                    // Create object from DataRow
                    IssueInfo modifyIssue = new IssueInfo(issueDr);

                    // Update the properties
                    modifyIssue.IssueSubject = modifyIssue.IssueSubject.ToUpper();

                    // Save the changes
                    IssueInfoProvider.SetIssueInfo(modifyIssue);
                }

                return(true);
            }
        }
        return(false);
    }
    /// <summary>
    /// Gets and updates dynamic issue. Called when the "Get and update issue" button is pressed.
    /// Expects the CreateDynamicIssue method to be run first.
    /// </summary>
    private bool GetAndUpdateDynamicIssue()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", CMSContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Prepare the parameters
            string where = "IssueNewsletterID = " + newsletter.NewsletterID;

            // Get the data
            DataSet issues = IssueInfoProvider.GetIssues(where, null);

            if (!DataHelper.DataSourceIsEmpty(issues))
            {
                // Create object from DataRow
                IssueInfo updateIssue = new IssueInfo(issues.Tables[0].Rows[0]);

                if (updateIssue != null)
                {
                    // Update the properties
                    updateIssue.IssueSubject = updateIssue.IssueSubject.ToLower();

                    // Save the changes
                    IssueInfoProvider.SetIssueInfo(updateIssue);

                    return(true);
                }
            }
        }
        return(false);
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        case "edit":
            string url = UIContextHelper.GetElementUrl("cms.newsletter", "EditNewsletterProperties", false, actionArgument.ToInteger(0));
            URLHelper.Redirect(url);
            break;

        case "delete":
            var newsletter = NewsletterInfoProvider.GetNewsletterInfo(ValidationHelper.GetInteger(actionArgument, 0));
            if (newsletter == null)
            {
                RedirectToAccessDenied(GetString("general.invalidparameters"));
            }

            if (!newsletter.CheckPermissions(PermissionsEnum.Delete, CurrentSiteName, CurrentUser))
            {
                RedirectToAccessDenied(newsletter.TypeInfo.ModuleName, "Configure");
            }

            // delete Newsletter object from database
            newsletter.Delete();

            break;
        }
    }
Exemple #14
0
    public override bool LoadData(ActivityInfo ai)
    {
        if ((ai == null) || (ai.ActivityType != PredefinedActivityType.NEWSLETTER_OPEN))
        {
            return(false);
        }

        // Get newsletter name
        int            newsletterId   = ai.ActivityItemID;
        NewsletterInfo newsletterInfo = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);

        if (newsletterInfo != null)
        {
            string subject = ValidationHelper.GetString(newsletterInfo.NewsletterDisplayName, null);
            ucDetails.AddRow("om.activitydetails.newsletter", subject);
        }

        // Get issue subject
        int       issueId   = ai.ActivityItemDetailID;
        IssueInfo issueInfo = IssueInfoProvider.GetIssueInfo(issueId);

        if (issueInfo != null)
        {
            string subject = ValidationHelper.GetString(issueInfo.IssueSubject, null);
            ucDetails.AddRow("om.activitydetails.newsletterissue", MacroSecurityProcessor.RemoveSecurityParameters(subject, true, null));
        }

        return(ucDetails.IsDataLoaded);
    }
    /// <summary>
    /// Gets and updates dynamic issue. Called when the "Get and update issue" button is pressed.
    /// Expects the CreateDynamicIssue method to be run first.
    /// </summary>
    private bool GetAndUpdateDynamicIssue()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", SiteContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Prepare the parameters
            var condition = new WhereCondition().WhereEquals("IssueNewsletterID", newsletter.NewsletterID);

            // Get the data
            var issues = IssueInfoProvider.GetIssues().Where(condition);
            if (issues.Any())
            {
                // Create object from DataRow
                IssueInfo updateIssue = issues.First();

                if (updateIssue != null)
                {
                    // Update the properties
                    updateIssue.IssueSubject = updateIssue.IssueSubject.ToLower();

                    // Save the changes
                    IssueInfoProvider.SetIssueInfo(updateIssue);

                    return(true);
                }
            }
        }
        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        IssueInfo issue = EditedObject as IssueInfo;

        if (issue == null)
        {
            RedirectToAccessDenied(GetString("general.invalidparameters"));
        }

        if (!issue.CheckPermissions(PermissionsEnum.Read, CurrentSiteName, CurrentUser))
        {
            RedirectToAccessDenied(issue.TypeInfo.ModuleName, "AuthorIssues");
        }

        var subscriber = GetSubscriber(NewsletterInfoProvider.GetNewsletterInfo(issue.IssueNewsletterID));

        // Switch culture to the site culture, so the e-mail isn't rendered in the editor's culture
        string culture = CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName);

        using (new CMSActionContext {
            ThreadCulture = CultureHelper.GetCultureInfo(culture)
        })
        {
            string htmlPage = NewsletterHelper.GetPreviewHTML(issue, subscriber);
            Response.Clear();
            Response.Write(htmlPage);
        }

        RequestHelper.EndResponse();
    }
Exemple #17
0
        public ActionResult Subscribe(NewsletterSubscribeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                // If the subscription data is not valid, displays the subscription form with error messages
                return(View(model));
            }

            // Gets the default Kentico contact provider
            IContactProvider contactProvider = Service <IContactProvider> .Entry();

            // Either gets an existing contact by email or creates a new contact object with the given email
            ContactInfo contact = contactProvider.GetContactForSubscribing(model.Email);

            // Gets a newsletter
            // Fill in the code name of your newsletter object in Kentico
            NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("SampleNewsletter", SiteContext.CurrentSiteID);

            // Prepares settings that configure the subscription behavior
            var subscriptionSettings = new NewsletterSubscriptionSettings()
            {
                RemoveAlsoUnsubscriptionFromAllNewsletters = true, // Subscription removes the given email address from the global opt-out list for all marketing emails (if present)
                SendConfirmationEmail = true,                      // Allows sending of confirmation emails for the subscription
                AllowOptIn            = true                       // Allows handling of double opt-in subscription for newsletters that have it enabled
            };

            // Subscribes the contact with the specified email address to the given newsletter
            SubscriptionService.Subscribe(contact, newsletter, subscriptionSettings);

            // Passes information to the view, indicating whether the newsletter requires double opt-in for subscription
            model.RequireDoubleOptIn = newsletter.NewsletterEnableOptIn;

            // Displays a view to inform the user that the subscription was successful
            return(View("SubscribeSuccess", model));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get newsletter id from querystring
        newsletterId = QueryHelper.GetInteger("newsletterid", 0);
        // Try to get nesletter display name
        string         newsName = string.Empty;
        NewsletterInfo news     = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);

        if (news != null)
        {
            newsName = news.NewsletterDisplayName;
        }

        // Initializes page title
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("Newsletter_Edit.Newsletters");
        breadcrumbs[0, 1]     = "~/CMSModules/Newsletters/Tools/Newsletters/Newsletter_List.aspx";
        breadcrumbs[0, 2]     = "newslettersContent";
        breadcrumbs[1, 0]     = newsName;
        breadcrumbs[1, 1]     = string.Empty;
        breadcrumbs[1, 2]     = string.Empty;

        CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        // Initialize tabs
        InitalizeMenu(news);
    }
    /// <summary>
    /// Deletes dynamic issue. Called when the "Delete issue" button is pressed.
    /// Expects the CreateDynamicIssue method to be run first.
    /// </summary>
    private bool DeleteDynamicIssue()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", SiteContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Prepare the parameters
            var condition = new WhereCondition().WhereEquals("IssueNewsletterID", newsletter.NewsletterID);

            // Get the data
            var issues = IssueInfoProvider.GetIssues().Where(condition);
            if (issues.Any())
            {
                // Create object from DataRow
                IssueInfo deleteIssue = issues.First();

                // Delete the dynamic issue
                IssueInfoProvider.DeleteIssueInfo(deleteIssue);

                return(deleteIssue != null);
            }
        }
        return(false);
    }
Exemple #20
0
    /// <summary>
    /// Handles multiple selector actions.
    /// </summary>
    protected void btnOk_Clicked(object sender, EventArgs e)
    {
        // Check permissions
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.newsletter", "ManageSubscribers"))
        {
            RedirectToAccessDenied("cms.newsletter", "ManageSubscribers");
        }
        // Return if no action was selected
        if (drpActions.SelectedValue.EqualsCSafe(SELECT, true))
        {
            return;
        }

        // Get selected items
        if (unigridNewsletters.SelectedItems.Count > 0)
        {
            foreach (string id in unigridNewsletters.SelectedItems)
            {
                var newsletter = NewsletterInfoProvider.GetNewsletterInfo(ValidationHelper.GetInteger(id, 0));
                if (newsletter == null)
                {
                    continue;
                }

                DoSubscriberAction(newsletter, drpActions.SelectedValue);
            }
        }

        unigridNewsletters.ResetSelection();
        unigridNewsletters.ReloadData();
    }
    /// <summary>
    /// Gets and bulk updates dynamic issues. Called when the "Get and bulk update issues" button is pressed.
    /// Expects the CreateDynamicIssue method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateDynamicIssues()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", SiteContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Prepare the parameters
            var condition = new WhereCondition().WhereEquals("IssueNewsletterID", newsletter.NewsletterID);

            // Get the data
            var issues = IssueInfoProvider.GetIssues().Where(condition);
            if (issues.Any())
            {
                // Loop through the individual items
                foreach (var issue in issues)
                {
                    // Update the properties
                    issue.IssueSubject = issue.IssueSubject.ToUpper();

                    // Save the changes
                    IssueInfoProvider.SetIssueInfo(issue);
                }

                return(true);
            }
        }
        return(false);
    }
    /// <summary>
    /// Creates static issue. Called when the "Create issue" button is pressed.
    /// </summary>
    private bool CreateStaticIssue()
    {
        // Get the newsletter
        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewStaticNewsletter", SiteContext.CurrentSiteID);

        if (newsletter != null)
        {
            // Create new static issue object
            IssueInfo newIssue = new IssueInfo();

            // Set the properties
            newIssue.IssueSubject                 = "My new static issue";
            newIssue.IssueNewsletterID            = newsletter.NewsletterID;
            newIssue.IssueSiteID                  = SiteContext.CurrentSiteID;
            newIssue.IssueText                    = "<?xml version=\"1.0\" encoding=\"utf-16\"?><content><region id=\"content\">Issue text</region></content>";
            newIssue.IssueUnsubscribed            = 0;
            newIssue.IssueSentEmails              = 0;
            newIssue.IssueTemplateID              = newsletter.NewsletterTemplateID;
            newIssue.IssueShowInNewsletterArchive = false;

            // Save the static issue
            IssueInfoProvider.SetIssueInfo(newIssue);

            return(true);
        }

        return(false);
    }
        public ActionResult Unsubscribe(UnsubscriptionModel model)
        {
            string invalidUrlMessage = ResHelper.GetString("DancingGoatMvc.News.InvalidUnsubscriptionLink");

            if (ModelState.IsValid)
            {
                bool emailIsValid = mEmailHashValidator.ValidateEmailHash(model.Hash, model.Email);

                if (emailIsValid)
                {
                    try
                    {
                        var issue = IssueInfoProvider.GetIssueInfo(model.IssueGuid, SiteContext.CurrentSiteID);

                        if (model.UnsubscribeFromAll)
                        {
                            // Unsubscribes if not already unsubscribed
                            if (!mUnsubscriptionProvider.IsUnsubscribedFromAllNewsletters(model.Email))
                            {
                                mSubscriptionService.UnsubscribeFromAllNewsletters(model.Email, issue?.IssueID);
                            }

                            model.UnsubscriptionResult = ResHelper.GetString("DancingGoatMvc.News.UnsubscribedAll");
                        }
                        else
                        {
                            var newsletter = NewsletterInfoProvider.GetNewsletterInfo(model.NewsletterGuid, SiteContext.CurrentSiteID);
                            if (newsletter != null)
                            {
                                // Unsubscribes if not already unsubscribed
                                if (!mUnsubscriptionProvider.IsUnsubscribedFromSingleNewsletter(model.Email, newsletter.NewsletterID))
                                {
                                    mSubscriptionService.UnsubscribeFromSingleNewsletter(model.Email, newsletter.NewsletterID, issue?.IssueID);
                                }

                                model.UnsubscriptionResult = ResHelper.GetString("DancingGoatMvc.News.Unsubscribed");
                            }
                            else
                            {
                                ModelState.AddModelError(String.Empty, invalidUrlMessage);
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        ModelState.AddModelError(String.Empty, invalidUrlMessage);
                    }
                }
                else
                {
                    ModelState.AddModelError(String.Empty, invalidUrlMessage);
                }
            }
            else
            {
                ModelState.AddModelError(String.Empty, invalidUrlMessage);
            }

            return(View(model));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get issue ID from querystring
        issueId = QueryHelper.GetInteger("issueid", 0);

        // Get newsletter issue and check its existence
        IssueInfo issue = IssueInfoProvider.GetIssueInfo(issueId);

        EditedObject = issue;

        string infoMessage         = null;
        bool   isABTest            = issue.IssueIsABTest;
        bool   sendingIssueAllowed = false;

        sendElem.Visible    = !isABTest;
        sendVariant.Visible = isABTest;

        if (!isABTest)
        {
            sendElem.IssueID      = issueId;
            sendElem.NewsletterID = issue.IssueNewsletterID;
            bool isSent = (issue.IssueMailoutTime != DateTimeHelper.ZERO_TIME) && (issue.IssueMailoutTime < DateTime.Now);
            infoMessage = (isSent ? GetString("Newsletter_Issue_Header.AlreadySent") : GetString("Newsletter_Issue_Header.NotSentYet"));

            // If resending is disabled check that the issue has 'Idle' status
            newsletter = NewsletterInfoProvider.GetNewsletterInfo(issue.IssueNewsletterID);
            if (newsletter != null)
            {
                sendingIssueAllowed = newsletter.NewsletterEnableResending || issue.IssueStatus == IssueStatusEnum.Idle;
            }
        }
        else
        {
            sendVariant.StopProcessing = (issueId <= 0);
            sendVariant.IssueID        = issueId;
            sendVariant.OnChanged     -= new EventHandler(sendVariant_OnChanged);
            sendVariant.OnChanged     += new EventHandler(sendVariant_OnChanged);
            sendVariant.ReloadData(!RequestHelper.IsPostBack());
            infoMessage         = sendVariant.InfoMessage;
            sendingIssueAllowed = sendVariant.SendingAllowed;
        }

        // Display additional information
        if (!String.IsNullOrEmpty(infoMessage))
        {
            ShowInformationInternal(infoMessage);
        }

        InitHeaderActions(isABTest && (issue.IssueStatus != IssueStatusEnum.Finished), sendingIssueAllowed);

        string scriptBlock = @"function RefreshPage() {{ document.location.replace(document.location); }}";

        ScriptHelper.RegisterClientScriptBlock(this, GetType(), "Actions", scriptBlock, true);

        if (!RequestHelper.IsPostBack() && (QueryHelper.GetInteger("sent", 0) == 1))
        {
            ShowConfirmation(GetString("Newsletter_Send.SuccessfullySent"));
        }
    }
    /// <summary>
    /// Deletes dynamic newsletter. Called when the "Delete newsletter" button is pressed.
    /// Expects the CreateDynamicNewsletter method to be run first.
    /// </summary>
    private bool DeleteDynamicNewsletter()
    {
        // Get the dynamic newsletter
        NewsletterInfo deleteNewsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewDynamicNewsletter", SiteContext.CurrentSiteID);

        // Delete the dynamic newsletter
        NewsletterInfoProvider.DeleteNewsletterInfo(deleteNewsletter);

        return(deleteNewsletter != null);
    }
    /// <summary>
    /// Deletes static newsletter. Called when the "Delete newsletter" button is pressed.
    /// Expects the CreateStaticNewsletter method to be run first.
    /// </summary>
    private bool DeleteStaticNewsletter()
    {
        // Get the static newsletter
        NewsletterInfo deleteNewsletter = NewsletterInfoProvider.GetNewsletterInfo("MyNewStaticNewsletter", CMSContext.CurrentSiteID);

        // Delete the static newsletter
        NewsletterInfoProvider.DeleteNewsletterInfo(deleteNewsletter);

        return(deleteNewsletter != null);
    }
        private void GenerateEmailCampaignSubscribers()
        {
            var contactGroupInfo = ContactGroupInfoProvider.GetContactGroupInfo(EmailCampaignContactGroup);
            var newsletter       = NewsletterInfoProvider.GetNewsletterInfo(NEWSLETTER_COFFEE_CLUB_MEMBERSHIP, _mSite.SiteID);

            SubscribeContactGroupToIssue(
                IssueInfoProvider.GetIssues().First(issue => issue.IssueNewsletterID == newsletter.NewsletterID),
                contactGroupInfo);
            AddContactsToSubscribedContactGroup(contactGroupInfo);
        }
        private void SubscribeContactWithEmailToNewsletter(string contactEmail, string newsletterCodeName)
        {
            var contact    = ContactInfoProvider.GetContactInfo(contactEmail);
            var newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterCodeName, site.SiteID);
            var fullName   = string.Format("{0} {1}", contact.ContactFirstName, contact.ContactLastName);

            var subscriber = CreateSubscriber(contact.ContactEmail, contact.ContactFirstName, contact.ContactLastName, fullName, contact);

            AssignSubscriberToNewsletter(newsletter.NewsletterID, subscriber);
            mNewsletterActivityGenerator.GenerateNewsletterSubscribeActivity(newsletter, subscriber.SubscriberID, contact.ContactID, site.SiteID);
        }
Exemple #29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        issueInfo = EditedObject as IssueInfo;

        if (issueInfo == null)
        {
            RedirectToAccessDenied(GetString("general.invalidparameters"));
        }

        if (!issueInfo.CheckPermissions(PermissionsEnum.Read, CurrentSiteName, CurrentUser))
        {
            RedirectToAccessDenied(issueInfo.TypeInfo.ModuleName, "Read");
        }

        InitAbTestingTab();

        rptEmailWidgets.DataSource = GetAvailableWidgets(issueInfo.IssueTemplateID);
        rptEmailWidgets.DataBind();

        alNoRecords.Visible = !rptEmailWidgets.HasData();

        // Set builder iframe
        builderIframe.Src = URLHelper.ResolveUrl($"~/CMSPages/Newsletters/GetEmailBuilderContent.ashx?issueid={issueInfo.IssueID}");

        // Initialize email properties control
        emailProperties.Enabled      = EditEnabled;
        emailProperties.IssueID      = issueInfo.IssueID;
        emailProperties.NewsletterID = issueInfo.IssueNewsletterID;
        emailProperties.Save        += EmailProperties_Save;

        if (!RequestHelper.IsAsyncPostback())
        {
            string moduleId             = "CMS.Newsletter/emailbuilder";
            var    zonesConfiguration   = Service.Resolve <IZonesConfigurationServiceFactory>().Create(issueInfo);
            var    localizationProvider = Service.Resolve <IClientLocalizationProvider>();
            var    newsletter           = NewsletterInfoProvider.GetNewsletterInfo(issueInfo.IssueNewsletterID);
            var    filter = new EmailBuilderContentFilter(issueInfo, newsletter);

            ScriptHelper.RegisterModule(this, "CMS/RegisterClientLocalization", localizationProvider.GetClientLocalization(moduleId));
            ScriptHelper.RegisterModule(this, "CMS.Newsletter/EmailBuilder", new
            {
                issueId = issueInfo.IssueID,
                enableWidgetManipulation = EditEnabled,
                emailContent             = zonesConfiguration.GetEmailContent(filter)
            });

            ScriptHelper.HideVerticalTabs(this);
            ScriptHelper.RefreshTabHeader(Page, issueInfo.Generalized.ObjectDisplayName);

            InitHeaderActions();
        }

        SetClientApplicationData();
    }
    /// <summary>
    /// Logs unsubscription activity if newsletter exists
    /// </summary>
    private void LogUnsubscriptionActivity(int newsletterId)
    {
        var newsletter = NewsletterInfoProvider.GetNewsletterInfo(newsletterId);

        if (newsletter == null)
        {
            return;
        }

        var activityLogger = Service.Resolve <INewslettersActivityLogger>();

        activityLogger.LogUnsubscribeFromSingleNewsletterActivity(newsletter);
    }