public static MailingListSubscriber GetByID(int MailingListSubscriberID, IEnumerable <string> includeList = null)
        {
            MailingListSubscriber obj = null;
            string key = cacheKeyPrefix + MailingListSubscriberID + GetCacheIncludeText(includeList);

            MailingListSubscriber tmpClass = null;

            if (Cache.IsEnabled)
            {
                if (Cache.IsEmptyCacheItem(key))
                {
                    return(null);
                }
                tmpClass = Cache[key] as MailingListSubscriber;
            }

            if (tmpClass != null)
            {
                obj = tmpClass;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    IQueryable <MailingListSubscriber> itemQuery = AddIncludes(entity.MailingListSubscriber, includeList);
                    obj = itemQuery.FirstOrDefault(n => n.MailingListSubscriberID == MailingListSubscriberID);
                }
                Cache.Store(key, obj);
            }

            return(obj);
        }
 public MailingListSubscriber(MailingListSubscriber objectToCopy)
 {
     Active                  = objectToCopy.Active;
     EntityID                = objectToCopy.EntityID;
     MailingListID           = objectToCopy.MailingListID;
     MailingListSubscriberID = objectToCopy.MailingListSubscriberID;
     NewsletterFormatID      = objectToCopy.NewsletterFormatID;
     SubscriberID            = objectToCopy.SubscriberID;
 }
Ejemplo n.º 3
0
        public static UnsubscribeUserReturnCode UnsubscribeUser(int mailingListID, string email)
        {
            ClearCache();

            // Find the Subscriber record by Email Address
            List <Subscriber> subs = Subscriber.SubscriberGetByEmail(email);

            if (subs.Count == 0)
            {
                return(UnsubscribeUserReturnCode.Never_Subscribed);
            }

            // Find the MailingList (validation purposes)
            MailingList ml = MailingList.GetByID(mailingListID);

            if (ml == null)
            {
                return(UnsubscribeUserReturnCode.Missing_MailingList);
            }

            // Find the MailingListSubscriber record (this could be better)
            List <MailingListSubscriber> mls
                = MailingListSubscriber.MailingListSubscriberGetBySubscriberID(subs[0].SubscriberID);

            if (mls.Count == 0)
            {
                return(UnsubscribeUserReturnCode.Never_Subscribed);
            }

            bool alreadyUnsubscribed = false;

            foreach (MailingListSubscriber t in mls)
            {
                if (t.MailingListID == mailingListID)
                {
                    alreadyUnsubscribed = true;
                    if (t.Active)
                    {
                        // Ok, the MailingListSubscriber is active, deactivate
                        t.Active = false;
                        t.Save();
                        return(UnsubscribeUserReturnCode.Success);
                    }
                }
            }

            if (alreadyUnsubscribed)
            {
                return(UnsubscribeUserReturnCode.Already_Unsubscribed);
            }

            return(UnsubscribeUserReturnCode.Already_Unsubscribed);
        }
Ejemplo n.º 4
0
        public static SubscribeUserReturnCode SubscribeUser(int mailingListID, string email, int newsletterFormatID, int?userID)
        {
            ClearCache();

            // Find the Subscriber record by Email Address
            List <Subscriber> subs = Subscriber.SubscriberGetByEmail(email);

            if (subs.Count == 0)
            {
                // Not yet a Subscriber, create new Subscriber
                Subscriber sub = new Subscriber();
                sub.Email = email;
                sub.DefaultNewsletterFormatID = newsletterFormatID;                 //this should be set to the user preference via SetSubscriberDefaultNewsletterFormatID
                sub.UserID = userID;
                sub.Save();
                subs.Add(sub);
            }

            // Find the MailingList (validation purposes)
            MailingList ml = MailingList.GetByID(mailingListID);

            if (ml == null)
            {
                return(SubscribeUserReturnCode.Missing_MailingList);
            }

            // Find the MailingListSubscriber record (this could be better)
            List <MailingListSubscriber> mls
                = MailingListSubscriber.MailingListSubscriberGetBySubscriberID(subs[0].SubscriberID);

            foreach (MailingListSubscriber t in mls)
            {
                if (t.MailingListID == mailingListID)
                {
                    //if subscriber isn't flagged as deleted...
                    if (t.Active)
                    {
                        // Ok, the MailingListSubscriber is active, return
                        t.NewsletterFormatID = newsletterFormatID;
                        t.Save();
                        return(SubscribeUserReturnCode.Already_Subscribed);
                    }
                    // MailingListSubscriber already exists but was inactive or was deleted from the subscriber list, reactivate and return success
                    subs[0].Deleted = false;
                    subs[0].Save();
                    t.Active             = true;
                    t.NewsletterFormatID = newsletterFormatID;
                    t.Save();
                    return(SubscribeUserReturnCode.Success);
                }
            }
            if (Settings.EnableMailingListLimitations && MailingListSubscriber.GetCountByMailingListIDActive(mailingListID, true) >= Settings.MaxNumberSubscribers)
            {
                return(SubscribeUserReturnCode.MailingList_Full);
            }
            //if MailingListSubscriber does not exist, create a new MailingListSubscriber
            MailingListSubscriber mlsNew = new MailingListSubscriber();

            mlsNew.MailingListID      = mailingListID;
            mlsNew.SubscriberID       = subs[0].SubscriberID;
            mlsNew.NewsletterFormatID = newsletterFormatID;
            mlsNew.Active             = true;
            mlsNew.EntityID           = Guid.NewGuid();
            mlsNew.Save();
            return(SubscribeUserReturnCode.Success);
        }