Пример #1
0
        /// <inheritdoc />
        public virtual bool AddSubscriber(SubscribeFormViewModel viewModel, out string error)
        {
            error = string.Empty;

            if (NewsletterValidator.IsValidEmail(viewModel.Email))
            {
                var newslettersManager = NewslettersManager.GetManager(this.Provider);

                // check if subscriber exists
                var email = viewModel.Email.ToLower();
                IQueryable <Subscriber> matchingSubscribers = newslettersManager.GetSubscribers().Where(s => s.Email == email);
                bool subscriberAlreadyInList = false;
                foreach (Subscriber s in matchingSubscribers)
                {
                    if (s.Lists.Any(ml => ml.Id == this.SelectedMailingListId))
                    {
                        subscriberAlreadyInList = true;
                        break;
                    }
                }

                if (subscriberAlreadyInList)
                {
                    // If the email has already been subscribed, consider it as success.
                    return(true);
                }
                else
                {
                    Subscriber subscriber = matchingSubscribers.FirstOrDefault();
                    if (subscriber == null)
                    {
                        subscriber           = newslettersManager.CreateSubscriber(true);
                        subscriber.Email     = viewModel.Email;
                        subscriber.FirstName = viewModel.FirstName != null ? viewModel.FirstName : string.Empty;
                        subscriber.LastName  = viewModel.LastName != null ? viewModel.LastName : string.Empty;
                    }

                    // check if the mailing list exists
                    if (newslettersManager.Subscribe(subscriber, this.SelectedMailingListId))
                    {
                        if (this.SuccessfullySubmittedForm == SuccessfullySubmittedForm.OpenSpecificPage)
                        {
                            viewModel.RedirectPageUrl = HyperLinkHelpers.GetFullPageUrl(this.PageId);
                        }

                        newslettersManager.SaveChanges();

                        return(true);
                    }
                }
            }
            error = Res.Get <SubscribeFormResources>().EmailAddressErrorMessageResourceName;
            return(false);
        }
Пример #2
0
        /// <inheritdoc />
        public virtual bool AddSubscriber(SubscribeFormViewModel viewModel, out string error)
        {
            error = string.Empty;

            if (NewsletterValidator.IsValidEmail(viewModel.Email))
            {
                var newslettersManager = NewslettersManager.GetManager(this.Provider);

                // check if subscriber exists
                var email = viewModel.Email.ToLower();
                IQueryable<Subscriber> matchingSubscribers = newslettersManager.GetSubscribers().Where(s => s.Email == email);
                bool subscriberAlreadyInList = false;
                foreach (Subscriber s in matchingSubscribers)
                {
                    if (s.Lists.Any(ml => ml.Id == this.SelectedMailingListId))
                    {
                        subscriberAlreadyInList = true;
                        break;
                    }
                }

                if (subscriberAlreadyInList)
                {
                    // If the email has already been subscribed, consider it as success.
                    return true;
                }
                else
                {
                    Subscriber subscriber = matchingSubscribers.FirstOrDefault();
                    if (subscriber == null)
                    {
                        subscriber = newslettersManager.CreateSubscriber(true);
                        subscriber.Email = viewModel.Email;
                        subscriber.FirstName = viewModel.FirstName != null ? viewModel.FirstName : string.Empty;
                        subscriber.LastName = viewModel.LastName != null ? viewModel.LastName : string.Empty;
                    }

                    // check if the mailing list exists
                    if (newslettersManager.Subscribe(subscriber, this.SelectedMailingListId))
                    {
                        if (this.SuccessfullySubmittedForm == SuccessfullySubmittedForm.OpenSpecificPage)
                        {
                            viewModel.RedirectPageUrl = HyperLinkHelpers.GetFullPageUrl(this.PageId);
                        }

                        newslettersManager.SaveChanges();

                        return true;
                    }
                }
            }
            error = Res.Get<SubscribeFormResources>().EmailAddressErrorMessageResourceName;
            return false;
        }
        public override bool AddSubscriber(SubscribeFormViewModel viewModel, out string error)
        {
            error = string.Empty;

            return true;
        }