Пример #1
0
        public ActionResult ActivateAccount(AccountViewModel item)
        {
            //Assign the current userId of the current user to variable userId
            var userId = Session["AccountInfo"] as string;

            //Remove the session variable
            Session.Remove("AccountInfo");

            //Check if variable userId is null
            if (String.IsNullOrEmpty(userId))

                //Redirect to Login form if it is null
                return RedirectToAction("Login", "Account");

            //Search and assing user the user which corresponds to the userId to variable requestedUser
            var requestedUser = db.Users.Where(x => x.Id == userId).FirstOrDefault();

            //Verify if the activation code entered and that of the account matches
            if (requestedUser.ActivationCode == item.ActivationCode)
            {
                //Search and assing user the user which corresponds to the userId to variable currentUser
                var currentUser = db.Users.Where(x => x.Id == userId).FirstOrDefault();

                //If currentUser is null. Display error page
                if (String.IsNullOrEmpty(currentUser.Id))
                    return RedirectToAction("Error404", "Home");

                //If the current user is not null assing null update the ActivationCode column of the current user
                currentUser.ActivationCode = null;

                //Save the changes into the database
                db.SaveChanges();

                //Redirect to the homepage
                return RedirectToAction("Index", "Home", new { message = ManageMessageId.ActivationCustomerSuccess });
            }
            return RedirectToAction("Login", "Account", new { message = ManageMessageId.ActivationCustomerFailure });
        }
Пример #2
0
 public ActionResult ActivateAccount()
 {
     var account = new AccountViewModel();
     return View(account);
 }