Esempio n. 1
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));
        }
Esempio n. 2
0
            public void SetUp()
            {
                mSite = CreateSiteInfo();
                SiteInfoProvider.SetSiteInfo(mSite);

                var emailTemplate = CreateEmailTemplateInfo(mSite.SiteID);

                EmailTemplateInfoProvider.SetEmailTemplateInfo(emailTemplate);

                mNewsletter = CreateNewsletterInfo(mSite.SiteID, emailTemplate.TemplateID);
                NewsletterInfoProvider.SetNewsletterInfo(mNewsletter);

                mNewsletterSubscriptionSettings = CreateNewsletterSubscriptionSettings(false);
                mNewsletterSubscriptionService  = new NewsletterSubscriptionService();
                Service.Use <IActivityLogService, ActivityLogServiceInMemoryFake>();

                SiteContext.CurrentSite = mSite;
            }
Esempio n. 3
0
        /// <summary>
        /// Subscribes <paramref name="contact"/> to the specified <paramref name="newsletter"/> using <paramref name="subscriptionSettings"/>.
        /// If a given contact hasn't been saved into database yet the method does so.
        /// </summary>
        /// <param name="contact">Subscriber to be subscribed</param>
        /// <param name="newsletter">Newsletter to subscribe to</param>
        /// <param name="subscriptionSettings">Subscription configuration</param>
        /// <returns>True if contact was subscribed by current call, false when contact had already been subscribed.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="contact"/> or <paramref name="newsletter"/> is null.</exception>
        public virtual bool Subscribe(ContactInfo contact, NewsletterInfo newsletter, NewsletterSubscriptionSettings subscriptionSettings)
        {
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            if (newsletter == null)
            {
                throw new ArgumentNullException(nameof(newsletter));
            }

            var subscriptionService = Service.Resolve <ISubscriptionService>();

            if (!subscriptionService.IsSubscribed(contact, newsletter))
            {
                if (contact.ContactID <= 0)
                {
                    ContactInfoProvider.SetContactInfo(contact);
                }

                subscriptionService.Subscribe(contact, newsletter, subscriptionSettings);
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewsletterSubscriptionService"/> class.
 /// </summary>
 /// <param name="siteName">The code name of the site which this service will work with</param>
 /// <param name="subscriptionSettings">Subscription configuration</param>
 public NewsletterSubscriptionService(string siteName, NewsletterSubscriptionSettings subscriptionSettings)
 {
     mSiteName             = siteName;
     mSubscriptionSettings = subscriptionSettings;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="NewsletterSubscriptionService"/> class.
        /// </summary>
        /// <param name="siteName">The code name of the site which this service will work with</param>
		/// <param name="subscriptionSettings">Subscription configuration</param>
        public NewsletterSubscriptionService(string siteName, NewsletterSubscriptionSettings subscriptionSettings)
        {
            mSiteName = siteName;
			mSubscriptionSettings = subscriptionSettings;
        }