예제 #1
0
        /// <summary>
        /// people can subscribe to the newsletters without registering on the site. This method is used to attach those existing subscriptions to the user upon registration
        /// </summary>
        /// <param name="siteUser"></param>
        public static void ClaimExistingSubscriptions(SiteUser siteUser)
        {
            SubscriberRepository subscriptions = new SubscriberRepository();
            List<LetterSubscriber> userSubscriptions = subscriptions.GetListByEmail(siteUser.SiteGuid, siteUser.Email);

            foreach (LetterSubscriber s in userSubscriptions)
            {

                if (s.UserGuid != siteUser.UserGuid)
                {
                    s.UserGuid = siteUser.UserGuid;
                    subscriptions.Save(s);
                }

                if (!s.IsVerified)
                {
                    subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty);
                    LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);

                }

            }

            List<LetterSubscriber> memberSubscriptions = subscriptions.GetListByUser(siteUser.SiteGuid, siteUser.UserGuid);

            RemoveDuplicates(memberSubscriptions);

            // commented out 2012-11-16 since we now give the user a chance to opt in the registration
            // then we should not force him in if he chose not to opt in

            //if (memberSubscriptions.Count == 0)
            //{
            //    string ipAddress = SiteUtils.GetIP4Address();
            //    //user has no previous subscriptions and just registered
            //    // lets give him the site subscriptions that are configured for opting in new users by default
            //    List<LetterInfo> allNewsletters = LetterInfo.GetAll(siteUser.SiteGuid);
            //    foreach (LetterInfo l in allNewsletters)
            //    {
            //        if ((l.ProfileOptIn) && (l.AvailableToRoles.Contains("All Users;")))
            //        {
            //            LetterSubscriber s = new LetterSubscriber();
            //            s.SiteGuid = siteUser.SiteGuid;
            //            s.LetterInfoGuid = l.LetterInfoGuid;
            //            s.UserGuid = siteUser.UserGuid;
            //            s.EmailAddress = siteUser.Email;
            //            s.IsVerified = true;
            //            s.UseHtml = true;
            //            s.IpAddress = ipAddress;
            //            subscriptions.Save(s);

            //        }

            //    }

            //}
        }
예제 #2
0
        private void RunTask()
        {
            // this is where the work gets done

            // Get a data table of up to 1000 users
            // who have not opted in but also have not previously
            // opted out and have valid email accounts and account is not locked
            DataTable dataTable = GetData();

            double completeRatio = .5;

            if (dataTable.Rows.Count == 0)
            {
                completeRatio = 1; //complete
                ReportStatus(completeRatio);
                return;

            }

            SubscriberRepository repository = new SubscriberRepository();

            int count = 0;

            foreach (DataRow row in dataTable.Rows)
            {
                Guid userGuid = new Guid(row["UserGuid"].ToString());
                string email = row["email"].ToString();

                LetterSubscriber s = new LetterSubscriber();
                s.SiteGuid = SiteGuid;
                s.UserGuid = userGuid;
                s.EmailAddress = email;
                s.LetterInfoGuid = LetterInfoGuid;
                s.UseHtml = true;
                s.IsVerified = true;

                repository.Save(s);

                count += 1;

                if (count > 20)
                {
                    ReportStatus(completeRatio);
                    count = 0;
                }

            }

            LetterInfo.UpdateSubscriberCount(LetterInfoGuid);
            ReportStatus(completeRatio);

            // repeat until the table comes back with 0 rows
            RunTask();
        }