public async Task <ActionResult> SendBulkResetEmail()
        {
            // get users
            var users = from u in db.Tokens
                        where u.User.Verified == true
                        select new SendBulkTokenEmailModel
            {
                TitleID   = u.User.TitleID,
                Intials   = u.User.Intials,
                Surname   = u.User.Surname,
                UserName  = u.User.UserName,
                TokenID   = u.Id,
                Email     = u.User.Email,
                IssueDate = u.IssueDate
            };

            foreach (var user in users)
            {
                string clientName = user.TitleID + " " + user.Intials + " " + user.Surname;

                bool success = NotificationsHelper.SendPasswordResetEmail(user.Email, clientName, ControllerContext);

                if (!success)
                {
                    Trace.WriteLine("Failed to send reset email to: " + user.Email + " during bulk email sending", "Reset Bulk Emails");
                }
            }

            ViewBag.Title = "Bulk Reset Emails";

            return(View("SendBulkVerificationEmail", await users.ToListAsync()));
        }
        public async Task <ActionResult> RequestResetToken(RequestTokenModel model)
        {
            var success = false;

            if (ModelState.IsValid)
            {
                ApplicationUser user = null;
                #region validate email
                bool   emailValid = false;
                string username   = "";
                string extension  = "";
                string email      = model.Email.ToLower();
                try
                {
                    username  = model.Email.Substring(0, model.Email.IndexOf('@')).ToLower();
                    extension = model.Email.Substring(model.Email.IndexOf('@') + 1).ToLower();

                    var userInfo = (from u in db.Users
                                    where u.UserName.Equals(username) && u.Email.Equals(email) && u.Verified == true
                                    select u);

                    // validate the email extension and username the student entered
                    var count = await userInfo.CountAsync();

                    if (count > 0)
                    {
                        emailValid = true;
                        user       = await userInfo.FirstAsync();
                    }
                    else
                    {
                        emailValid = false;
                        ModelState.AddModelError("Email", "The student email address entered is not valid");
                    }
                }
                catch (Exception e)
                {
                    emailValid = false;
                    Trace.WriteLine(e.Message, "Reset Token Request");
                    ModelState.AddModelError("Email", "The student email address entered is not valid");
                }
                #endregion

                #region send reset email
                if (emailValid)
                {
                    string clientName = user.TitleID + " " + user.Intials + " " + user.Surname;

                    success = NotificationsHelper.SendPasswordResetEmail(user.Email, clientName, this.ControllerContext);
                    if (!success)
                    {
                        Trace.WriteLine(String.Format("*** WARNING:  A reset email to '{0}' failed.", user.Email));
                        ModelState.AddModelError("", "An error occured while sending a reset password email. Please try again later");
                    }
                }
                #endregion
            }

            ViewBag.Success = success;
            return(View());
        }