public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);
                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return View("Register");
                }

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                MandrillMailer mandrillMailer = new MandrillMailer();
                mandrillMailer.SendForgotPasswordReset(model.Email, callbackUrl);

                TempData["SuccessAlertCustom"] = @"<strong>Success!</strong> A Password Reset email has been sent.";

                return RedirectToAction("Login", "Account");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> SendNewWebAccountEmail(MembershipAccountLoginSetupViewModel model)
        {
            var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
            var resultFromAccountCreation = await UserManager.CreateAsync(user, model.Password);
            string callbackUrl = null;

            if (resultFromAccountCreation.Succeeded)
            {
                var emailCode = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                var resultFromEmailConfirmation = await UserManager.ConfirmEmailAsync(user.Id, emailCode);

                var resultFromAddingMembershipRole = await UserManager.AddToRolesAsync(user.Id, AppRole.ActiveMember.ToString());

                if (resultFromAddingMembershipRole.Succeeded)
                {
                    using (UnitOfWork unitOfWork = new UnitOfWork(new ChurchManagerEntities()))
                    {
                        //Assign web account to a user
                        unitOfWork.context.Database.ExecuteSqlCommand(@"
                                                                UPDATE [dbo].[AspNetUsers]
                                                                   SET [PersonPrimaryInfoID] = @PersonPrimaryInfoID
                                                                 WHERE [Id] = @UserID
                                                                ", new SqlParameter("@UserID", user.Id), new SqlParameter("@PersonPrimaryInfoID", model.PersonPrimaryInfoID));

                        //Prompt user account Update
                        unitOfWork.context.Database.ExecuteSqlCommand(@"
                                                                UPDATE [dbo].[PersonPrimaryInfo]
                                                                    SET [PromptContactInformationUpdate] = 1
                                                                WHERE PersonPrimaryInfoID = @PersonPrimaryInfoID
                                                                ", new SqlParameter("@PersonPrimaryInfoID", model.PersonPrimaryInfoID));
                    }
                }

                //string code = UserManager.GeneratePasswordResetToken<ApplicationUser, string>(user.Id);
                //callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                ////if (HttpContext.Request.IsLocal)
                ////{
                ////    MandrillMailer mandrillMailer = new MandrillMailer();
                ////    mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl);
                ////}

                //MandrillMailer mandrillMailer = new MandrillMailer();
                //mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl);

                //TempData["SuccessAlertCustom"] = @"<strong>Success!</strong> Membership Enrollment Email Sent";
            }
            else
            {
                user = UserManager.FindByEmail(user.Email);
            }

            string code = UserManager.GeneratePasswordResetToken<ApplicationUser, string>(user.Id);
            callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

            //if (HttpContext.Request.IsLocal)
            //{
            //    MandrillMailer mandrillMailer = new MandrillMailer();
            //    mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl);
            //}

            MandrillMailer mandrillMailer = new MandrillMailer();
            mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl);

            TempData["SuccessAlertCustom"] = @"<strong>Success!</strong> Membership Enrollment Email Sent";

            if (HttpContext.Request.IsLocal)
            {
                return RedirectToAction("ConfirmLink", new { link = callbackUrl });
            }
            else
            {
                return RedirectToAction("Index", "Person");
            }
        }
        private void SendConfirmationEmail(string userId, string code, string email)
        {
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = userId, code = code }, protocol: Request.Url.Scheme);
            // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
            //ViewBag.Link = callbackUrl;

            MandrillMailer mandrillMailer = new MandrillMailer();
            mandrillMailer.SendAccountValidation(email, callbackUrl);
        }