public async Task <IActionResult> ResendVerificationEmailPost(long id,
                                                                      AdminResendVerificationEmailViewModel viewModel)
        {
            var user = SharedBusinessLogic.DataRepository.Get <User>(id);

            viewModel.User = user;

            if (user.EmailVerifiedDate != null)
            {
                viewModel.AddErrorFor <AdminResendVerificationEmailViewModel, object>(
                    m => m.OtherErrorMessagePlaceholder,
                    "This user's email address has already been verified");
                return(View("ResendVerificationEmail", viewModel));
            }

            viewModel.ParseAndValidateParameters(Request, m => m.Reason);
            if (viewModel.HasAnyErrors())
            {
                return(View("ResendVerificationEmail", viewModel));
            }

            auditLogger.AuditChangeToUser(
                this,
                AuditedAction.AdminResendVerificationEmail,
                user,
                new
            {
                viewModel.Reason
            }
                );

            var verifyCode = Encryption.EncryptQuerystring(user.UserId + ":" + user.Created.ToSmallDateTime());

            user.EmailVerifyHash     = Crypto.GetSHA512Checksum(verifyCode);
            user.EmailVerifySendDate = VirtualDateTime.Now;
            SharedBusinessLogic.DataRepository.SaveChangesAsync().Wait();

            var verifyUrl = Url.Action("VerifyEmail", "Account", new { vcode = verifyCode }, "https");

            if (!_adminService.SharedBusinessLogic.SendEmailService.SendCreateAccountPendingVerificationAsync(verifyUrl, user.EmailAddress).Result)
            {
                viewModel.AddErrorFor <AdminResendVerificationEmailViewModel, object>(
                    m => m.OtherErrorMessagePlaceholder,
                    "Error whilst re-sending verification email. Please try again in a few minutes.");
                return(View("ResendVerificationEmail", viewModel));
            }

            return(View("VerificationEmailSent", user));
        }
        public IActionResult ResendVerificationEmailPost(long id, AdminResendVerificationEmailViewModel viewModel)
        {
            User user = dataRepository.Get <User>(id);

            viewModel.User = user;

            if (user.EmailVerifiedDate != null)
            {
                viewModel.AddErrorFor(
                    m => m.OtherErrorMessagePlaceholder,
                    "This user's email address has already been verified");
                return(View("ResendVerificationEmail", viewModel));
            }

            viewModel.ParseAndValidateParameters(Request, m => m.Reason);
            if (viewModel.HasAnyErrors())
            {
                return(View("ResendVerificationEmail", viewModel));
            }

            auditLogger.AuditChangeToUser(
                AuditedAction.AdminResendVerificationEmail,
                user,
                new
            {
                viewModel.Reason
            },
                User);

            string verificationCode = Guid.NewGuid().ToString("N");
            string verificationUrl  = Url.Action(
                "VerifyEmail",
                "AccountCreation",
                new { code = verificationCode },
                "https");

            emailSendingService.SendAccountVerificationEmail(user.EmailAddress, verificationUrl);
            user.EmailVerifyHash     = verificationCode;
            user.EmailVerifySendDate = VirtualDateTime.Now;

            dataRepository.SaveChanges();

            return(View("VerificationEmailSent", user));
        }