Пример #1
0
        private void DoUnsubscribe()
        {
            if (subscriptionGuid != Guid.Empty)
            {
                LetterSubscriber s = subscriptions.Fetch(subscriptionGuid);
                if (s == null)
                {
                    ShowNotFoundMessge();
                    return;
                }
                subscriptions.Delete(s);
                LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);
                lblUnsubscribe.Text = Resource.NewsletterUnsubscribeSuccess;

                btnUnsubscribeConfirm.Visible = false;
                lblUnsubscribe.Visible        = true;
                return;
            }

            LetterInfo letterInfo = new LetterInfo(letterInfoGuid);

            if (letterInfo.LetterInfoGuid == Guid.Empty)
            {
                ShowNotFoundMessge();
                return;
            }

            List <LetterSubscriber> userSubscriptions = subscriptions.GetListByUser(siteSettings.SiteGuid, userGuid);

            bool unsubscribed = false;

            foreach (LetterSubscriber s in userSubscriptions)
            {
                if (s.LetterInfoGuid == letterInfoGuid)
                {
                    subscriptions.Delete(s);
                    unsubscribed = true;
                    LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);
                }
            }

            if (unsubscribed)
            {
                lblUnsubscribe.Text = string.Format(CultureInfo.InvariantCulture,
                                                    Resource.NewsletterUnsubscribeSuccessFormatString,
                                                    letterInfo.Title);

                btnUnsubscribeConfirm.Visible = false;
                lblUnsubscribe.Visible        = true;
            }
            else
            {
                ShowNotFoundMessge();
            }
        }
Пример #2
0
        public async void SubscriberRepositoryTest()
        {
            var repo = new SubscriberRepository(_logger, false);

            var firstSubscriber = new Subscriber("Amir", "*****@*****.**");
            await repo.AddAsync(firstSubscriber);

            var id = firstSubscriber.Id;

            repo.Detach(firstSubscriber);

            var secondSubscriber = new Subscriber("Amir", "*****@*****.**");

            await Assert.ThrowsAsync <Microsoft.EntityFrameworkCore.DbUpdateException>(
                () => repo.AddAsync(secondSubscriber)
                );

            Assert.Throws <Microsoft.EntityFrameworkCore.DbUpdateException>(
                () => {
                repo.Add(secondSubscriber);
            });

            //we should reconnect to see the deleted objects
            repo = new SubscriberRepository(_logger, false);

            repo.Delete(id);

            var count = repo.GetAll().Count();

            Assert.Equal(0, count);
        }
Пример #3
0
        public static bool DeleteSubscriber(int id)
        {
            try
            {
                var repo = new SubscriberRepository();
                repo.Delete(id);
                return(true);
            }
            catch (LocalException ex)
            {
            }

            return(false);
        }
Пример #4
0
        void grdSubscribers_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            string strG = e.CommandArgument.ToString();

            switch (e.CommandName)
            {
            case "DeleteSubscriber":

                if (strG.Length == 36)
                {
                    Guid             subscriptionGuid = new Guid(strG);
                    LetterSubscriber s = subscriptions.Fetch(subscriptionGuid);
                    if (s != null)
                    {
                        subscriptions.Delete(s);
                    }

                    LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);

                    WebUtils.SetupRedirect(this, Request.RawUrl);
                }

                break;

            case "SendVerification":

                if (strG.Length == 36)
                {
                    Guid             subscriptionGuid = new Guid(strG);
                    LetterSubscriber s          = subscriptions.Fetch(subscriptionGuid);
                    LetterInfo       letterInfo = new LetterInfo(letterInfoGuid);

                    NewsletterHelper.SendSubscriberVerificationEmail(
                        SiteRoot,
                        s.EmailAddress,
                        s.SubscribeGuid,
                        letterInfo,
                        siteSettings);
                }

                WebUtils.SetupRedirect(this, Request.RawUrl);

                break;
            }
        }
        private static void RemoveDuplicates(List <LetterSubscriber> userSubscriptions)
        {
            SubscriberRepository    subscriptions      = new SubscriberRepository();
            List <LetterSubscriber> cleanSubscriptions = new List <LetterSubscriber>();
            List <LetterSubscriber> duplicates         = new List <LetterSubscriber>();

            foreach (LetterSubscriber s in userSubscriptions)
            {
                if (!ContainsSubscription(cleanSubscriptions, s.LetterInfoGuid))
                {
                    cleanSubscriptions.Add(s);
                }
                else
                {
                    duplicates.Add(s);
                }
            }

            foreach (LetterSubscriber s in duplicates)
            {
                subscriptions.Delete(s, false);
            }
        }
        void grdSubscribers_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "DeleteSubscriber":

                string strG = e.CommandArgument.ToString();
                if (strG.Length == 36)
                {
                    Guid             subscriptionGuid = new Guid(strG);
                    LetterSubscriber s = subscriptions.Fetch(subscriptionGuid);
                    if (s != null)
                    {
                        subscriptions.Delete(s);
                    }

                    LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);

                    WebUtils.SetupRedirect(this, Request.RawUrl);
                }

                break;
            }
        }
Пример #7
0
        void btnSavePreferences_Click(object sender, EventArgs e)
        {
            foreach (LetterInfo availableSubscription in siteAvailableSubscriptions)
            {
                string controlID = "chk" + availableSubscription.LetterInfoGuid.ToString();

                if (Request.Params.Get(controlID) != null)
                {
                    if (!IsSubscribed(availableSubscription.LetterInfoGuid))
                    {
                        //subscribe
                        LetterSubscriber subscriber = new LetterSubscriber();
                        subscriber.SiteGuid       = siteSettings.SiteGuid;
                        subscriber.LetterInfoGuid = availableSubscription.LetterInfoGuid;
                        subscriber.UserGuid       = siteUser.UserGuid;
                        subscriber.EmailAddress   = siteUser.Email.ToLower();
                        subscriber.IsVerified     = true;
                        subscriber.UseHtml        = rbHtmlFormat.Checked;
                        subscriber.IpAddress      = SiteUtils.GetIP4Address();
                        subscriptions.Save(subscriber);

                        LetterInfo.UpdateSubscriberCount(availableSubscription.LetterInfoGuid);
                    }
                    else
                    {
                        // user is subscribed already
                        foreach (LetterSubscriber s in userSubscriptions)
                        {
                            if (s.LetterInfoGuid == availableSubscription.LetterInfoGuid)
                            {
                                if (s.UseHtml != rbHtmlFormat.Checked)
                                {
                                    s.UseHtml = rbHtmlFormat.Checked;
                                    subscriptions.Save(s);
                                }
                                if (!s.IsVerified)
                                {
                                    subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty);
                                    LetterInfo.UpdateSubscriberCount(availableSubscription.LetterInfoGuid);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (IsSubscribed(availableSubscription.LetterInfoGuid))
                    {
                        // unsubscribe
                        foreach (LetterSubscriber s in userSubscriptions)
                        {
                            if (s.LetterInfoGuid == availableSubscription.LetterInfoGuid)
                            {
                                subscriptions.Delete(s);
                            }
                        }


                        LetterInfo.UpdateSubscriberCount(availableSubscription.LetterInfoGuid);
                    }
                }
            }

            GetSubscriptions();
            BindPreferences();
            lblUnverifiedWarning.Visible = false;
            //btnSavePreferences.Text = Resource.NewsletterSavePreferencesButton;
            System.Threading.Thread.Sleep(1000);

            UpdatePanel1.Update();
        }