Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Email,HeardAbout,SignUpReason")] Newsletter newsletter)
        {
            if (ModelState.IsValid)
            {
                var isSubscribed = await _newsletterRepository.IsSubscribed(newsletter.Email);

                if (!isSubscribed)
                {
                    _newsletterRepository.Subscribe(newsletter);
                    await _newsletterRepository.SaveAll();

                    TempData["success"] = "Thank you for singning up to our newsletter";

                    return(RedirectToAction(nameof(Create)));
                }
                ModelState.AddModelError("Email", "Email is already registered");
                return(View(newsletter));
            }

            return(View(newsletter));
        }