示例#1
0
        public ActionResult Signup(string Email)
        {
            NewsletterSignup signup = repo.GetFirst <NewsletterSignup>(ns => ns.Email == Email);

            if (signup == null)
            {
                signup = new NewsletterSignup()
                {
                    Email = Email, VerificationToken = tokenGenerator.Generate(16), Verified = false
                };
                repo.Create <NewsletterSignup>(signup);
            }
            else
            {
                signup.VerificationToken = tokenGenerator.Generate(16);
                repo.Update <NewsletterSignup>(signup);
            }
            repo.Save();

            MailMessage mail = new MailMessage();

            mail.To.Add(new MailAddress(Email));
            var link = new Uri(HttpContext.Request.Url, Url.Action("Verify", new { token = signup.VerificationToken }));

            mail.Body       = String.Format("Welkom bij de CinemaTicketSystem nieuwsbrief,<br><a href=\"{0}\">Valideer je e-mailadres.</a>", link);
            mail.IsBodyHtml = true;
            mailer.Send(mail);

            return(View(signup));
        }
示例#2
0
        public EmptyResult EmailSignUp()
        {
            var emailAddress = Request["emailAddress"];

            if (string.IsNullOrWhiteSpace(emailAddress))
            {
                throw new ArgumentNullException("emailAddress");
            }

            // Create It
            var newsletterSignup = new NewsletterSignup
            {
                EmailAddress = emailAddress,
                Source       = "HomePage",
                IPAddress    = Request.UserHostAddress,
                DateCreated  = DateTime.Now
            };

            // Save It
            using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
            {
                this.MarketingService.AddNewsletterSignup(newsletterSignup);
                unitOfWork.Commit();
            }

            return(new EmptyResult());
        }
 // ARRANGE — constructor behaves the same as [SetUp]
 public HomeControllerTests()
 {
     contactRepo = new FakeContactFormRepository();
     signupRepo  = new FakeNewsletterSignupRepository();
     spellRepo   = new FakeSpellRepository();
     controller  = new HomeController(new NullLogger <HomeController>(), contactRepo, signupRepo, spellRepo);
     message     = new ContactForm()
     {
         Name    = "Luminous Nox-Lupin",
         Email   = "*****@*****.**",
         Phone   = "737-555-9993",
         Message = "Lorem ipsum dolor sit amet."
     };
     email = new NewsletterSignup()
     {
         EmailAddress = "*****@*****.**"
     };
     spell = new Spell()
     {
         Title       = "Excepteur Sint Occaecat",
         Enchantment = "Lorem ipsum dolor sit amet.",
         Intention   = "Knowledge",
         MagicType   = "White",
         User        = new AppUser()
         {
             UserName  = "******",
             FirstName = "Ravinia",
             LastName  = "Blaque"
         },
         Filename = "xyzy.jpg"
     };
     spellRepo.AddSpell(spell);
 }
示例#4
0
        public ActionResult Verify(string token)
        {
            NewsletterSignup signup = repo.GetFirst <NewsletterSignup>(ns => ns.VerificationToken == token);

            if (signup != null)
            {
                signup.Verified          = true;
                signup.VerificationToken = null;
                repo.Update <NewsletterSignup>(signup);
                repo.Save();
            }

            return(View(signup));
        }
        public void AddNewsletterSignupTest()
        {
            // Create fake TempDataDictionary to use TempData in controller method
            ITempDataProvider tempDataProvider = Mock.Of <ITempDataProvider>();
            HttpContext       httpContext      = new DefaultHttpContext();

            controller.TempData = new TempDataDictionary(httpContext, tempDataProvider);
            // add email registration
            controller.Newsletter(email);
            // confirm email was added to repo
            NewsletterSignup e = signupRepo.GetEmail(email.EmailAddress);

            Assert.Equal(email.EmailAddress, e.EmailAddress);
        }
示例#6
0
        /// <summary>
        /// Adds a Newsletter Signup
        /// </summary>
        public void AddNewsletterSignup(NewsletterSignup newsletterSignup)
        {
            if (newsletterSignup == null)
            {
                throw new ArgumentNullException("newsletterSignup");
            }

            // Ignore the Request if Email Already Exists
            if (this.Repository.GetSet <NewsletterSignup>().Any(x => x.EmailAddress == newsletterSignup.EmailAddress))
            {
                return;
            }

            this.Repository.Add(newsletterSignup);
        }
示例#7
0
 public IActionResult Newsletter(NewsletterSignup n)
 {
     if (ModelState.IsValid)
     {
         // save to database
         if (n.EmailAddress != null)
         {
             signupRepo.AddSignup(n);
         }
         // send to view
         TempData["RegistrationAddress"] = n.EmailAddress;
     }
     // Redirect to returnUrl
     return(RedirectToAction("Index", "Home"));
 }
示例#8
0
        public async Task <IActionResult> Create(NewsletterSignup signup)
        {
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "All fields are required. Please fill them and resubmit.";
                return(View("Index", signup));
            }

            await _mailSender.Send(new SendMail
            {
                Name  = signup.Name,
                Email = signup.Email
            });

            TempData["Success"] = "Thanks for registering with us. You'll get an email shortly.";

            return(RedirectToAction("Index"));
        }