Пример #1
0
        public async Task <ActionResult> Create(long id, [Bind(Include = AllowedFields)] MailingListSubscriber mailingListSubscriber)
        {
            if (ModelState.IsValid)
            {
                var mailinglist = await db.ActiveMailingLists.Where(m => m.AllowSubscribe).FindAsync(id);

                if (mailinglist != null)
                {
                    MailingListSubscriber existing = await db.ActiveMailingListSubscribers.FirstOrDefaultAsync(s => s.Email == mailingListSubscriber.Email && s.MailingList.Id == mailinglist.Id);

                    if (existing == null)
                    {
                        mailinglist.Subscribers.Add(mailingListSubscriber);
                        await db.SaveChangesAsync();
                    }
                    else
                    {
                        mailingListSubscriber = existing;
                    }
                    if (!mailingListSubscriber.Enabled)
                    {
                        EmailSender sender = new EmailSender(
                            mailinglist.Name + " - Confirm Subscription",
                            string.Format("Confirm your email address by following this link: <br/><a href=\"{0}\">{0}</a>",
                                          string.Format("http://{0}/MailingListSubscribers/Verify/{1}", Settings.CanonicalHostName, mailingListSubscriber.Verification)),
                            mailingListSubscriber.Email);
                        sender.ToName = mailingListSubscriber.FullName();
                        sender.IsHTML = true;
                        sender.Execute();
                    }

                    if (Roles.UserInAnyRole(User, Roles.ListManagers))
                    {
                        return(RedirectToMailingList(id));
                    }
                    else
                    {
                        return(RedirectToAction("Confirm"));
                    }
                }
                else
                {
                    return(HttpNotFound());
                }
            }

            return(View(mailingListSubscriber));
        }
Пример #2
0
        public async Task <ActionResult> Delete(long id)
        {
            MailingListSubscriber mailingListSubscriber = await db.ActiveMailingListSubscribers.FindAsync(id);

            if (mailingListSubscriber == null)
            {
                return(HttpNotFound());
            }
            var mailingListId = mailingListSubscriber.MailingList.Id;

            db.MailingListSubscribers.Remove(mailingListSubscriber);
            await db.SaveChangesAsync();

            SetSuccessMessage("{0} was removed successfully!", mailingListSubscriber.FullName());

            return(RedirectToMailingList(mailingListId));
        }
Пример #3
0
        public async Task <ActionResult> Edit([Bind(Include = AllowedFields)] MailingListSubscriber subscriber)
        {
            if (ModelState.IsValid)
            {
                MailingListSubscriber mailingListSubscriber = await db.ActiveMailingListSubscribers.FindAsync(subscriber.Id);

                if (mailingListSubscriber == null)
                {
                    return(HttpNotFound());
                }
                mailingListSubscriber.Update(subscriber);

                db.Entry(mailingListSubscriber).State = EntityState.Modified;
                await db.SaveChangesAsync();

                SetSuccessMessage("List subscriber {0} was updated successfully!", mailingListSubscriber.FullName());

                return(RedirectToMailingList(mailingListSubscriber.MailingList.Id));
            }

            return(Auto(subscriber));
        }