public ActionResult ResetPassword(ChangePassword model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (TrainingAssessmentEntities dc = new TrainingAssessmentEntities())
                {
                    var user = dc.tblEmployees.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password          = Crypto.Hash(model.NewPassword);
                        user.ResetPasswordCode = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }
            ViewBag.Message = message;
            return(View(model));
        }
        public ActionResult ForgotPassword(string EmailID)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (TrainingAssessmentEntities dc = new TrainingAssessmentEntities())
            {
                var account = dc.tblEmployees.Where(a => a.EmpEmailId == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SenderVerificationLinkEmail(account.EmpEmailId, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;
                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                    //in our model class in part 1
                    dc.Configuration.ValidateOnSaveEnabled = false;
                    dc.SaveChanges();
                    message = "Reset password link has been sent to your email id.";
                }
                else
                {
                    message = "Account not found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
        public ActionResult Registration([Bind(Exclude = "VerifyEmail,Activation")] tblEmployee user)
        {
            bool   Status  = false;
            string message = "";

            //
            // Model Validation
            if (ModelState.IsValid)
            {
                #region //Email is already Exist
                var isExist = IsEmailExist((user.EmpEmailId));
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion

                #region Generate Activation Code
                user.Activation = Guid.NewGuid();
                #endregion

                #region  Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //
                #endregion
                user.VerifyEmail = false;

                #region Save to Database
                using (TrainingAssessmentEntities dc = new TrainingAssessmentEntities())
                {
                    dc.tblEmployees.Add(user);
                    dc.SaveChanges();

                    //Send Email to User
                    SenderVerificationLinkEmail(user.EmpEmailId, user.Activation.ToString());
                    message = "Registration successfully done. Account activation link " +
                              " has been sent to your email id:" + user.EmpEmailId;
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (TrainingAssessmentEntities dc = new TrainingAssessmentEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                                                                // Confirm password does not match issue on save changes
                var v = dc.tblEmployees.Where(a => a.Activation == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.VerifyEmail = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }