Exemplo n.º 1
0
        public UserEmailDetails GetUserEmail(int id)
        {
            var user = new TheWholeUser()
            {
                Id           = 1,
                EmailAddress = "*****@*****.**",
                Name         = "User Name",
                PhoneNumber  = "555-369-8874"
            };

            UserEmailDetails emailData = new UserEmailDetails()
            {
                EmailAddress = user.EmailAddress
            };

            return(emailData);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(UserEmailDetails userEmail)
        {
            _logger.LogDebug($"{GetType().Name}.{nameof(Index)} method called...");
            ViewData["ErrorMessage"] = string.Empty;

            RecaptchaResponse recaptcha = await _recaptcha.Validate(Request);

            IActionResult result = View();

            if (!recaptcha.success)
            {
                ViewData["ErrorMessage"] = $"There was an error validating reCAPTCHA. Please try again!";
                ModelState.AddModelError("", "There was an error validating reCAPTCHA. Please try again!");
            }
            else
            {
                try
                {
                    if (!string.IsNullOrEmpty(userEmail?.Email))
                    {
                        EmailList emailListItem = new EmailList()
                        {
                            Id          = Guid.NewGuid(),
                            Email       = userEmail.Email,
                            IsValidated = false,
                            DateCreated = DateTime.UtcNow
                        };

                        _emailListRepository.Add(emailListItem);
                        _unitOfWork.Save();

                        if (!await SendEmailMessage(this.HttpContext, emailListItem.Id, emailListItem.Email))
                        {
                            ViewData["ErrorMessage"] = "Unable to send confirmation email";
                        }
                        else
                        {
                            this.HttpContext.Session.Set("Email", Encoding.UTF8.GetBytes(userEmail.Email));

                            result = Redirect($"/Home/ValidateEmail/?e={userEmail?.Email}");
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    _logger.LogError(ex, ex.Message);
                    ViewData["ErrorMessage"] = "This email has already been submitted.";
                }
                catch (SqlException ex)
                {
                    _logger.LogError(ex, ex.Message);
                    if (ex.Message.ToLower().Contains("cannot insert duplicate key"))
                    {
                        ViewData["ErrorMessage"] = "This email has already been submitted.";
                    }
                    else
                    {
                        ViewData["ErrorMessage"] = "There was a critical failure saving to the database.";
                    }
                }
            }

            return(result);
        }