public ActionResult AccountChangeName() { if (!IsLoggedIn()) { return(RedirectToAction("Index", "Home")); } var account = (Account)Session["Loggedin_Account"]; var changeAccountModel = new AccountChangeViewModel { Firstname = account.Firstname, Lastname = account.Lastname }; return(View(changeAccountModel)); }
public ActionResult AccountChangeName(AccountChangeViewModel model) { if (!IsLoggedIn()) { return(RedirectToAction("Index", "Home")); } var account = (Account)Session["Loggedin_Account"]; if (ModelState.IsValid) { if (account.Password == Helpers.Encrypt.GenerateSHA512String(model.CurrentPassword)) { if (model.Firstname != null || model.Lastname != null) { account.Firstname = model.Firstname; account.Lastname = model.Lastname; var result = _accountRepository.Update(account); } else { ModelState.AddModelError("Error", "Enter both first and last name"); } } else { ModelState.AddModelError("Error", "The provided password is incorrect"); } } var accountChangeViewModel = new AccountChangeViewModel { Firstname = account.Firstname, Lastname = account.Lastname }; return(RedirectToAction("Index", "Account") ); }