public ActionResult Edit([FromForm] UserAccountBuilder userAccountAttempt) { if (LoggedInUser(out UserAccount account)) { UserAccount updatedFields = userAccountAttempt.CreateUserAccount(hasher); //Check for which fields are being updated, since the forms are exclusive these checks will be as well. //First or Last Name form: if (!string.IsNullOrEmpty(updatedFields.FirstName) || !string.IsNullOrEmpty(updatedFields.LastName)) { //update functions compare values, only update on change accountService.UpdateAccountFirstName( updatedFields.FirstName, account, changeService); accountService.UpdateAccountLastName( updatedFields.LastName, account, changeService); } //Email form: else if (!string.IsNullOrEmpty(updatedFields.Email)) { accountService.UpdateAccountEmail( updatedFields.Email, account, changeService); } //Password form else if (!string.IsNullOrEmpty(updatedFields.PasswordHash)) { accountService.UpdateAccountPassword( updatedFields.PasswordHash, account, changeService); } changeService.StoreChanges(); return(RedirectToAction("Details")); } else { return(RedirectToAction("Login")); } }
private bool CreateNewAccount(UserAccountBuilder userAccountAttempt) { //create the account from the form data UserAccount user = userAccountAttempt.CreateUserAccount(hasher); bool accountCreated = accountService.AddAccount(user); if (accountCreated) { changeService.AddChange(user, "New Account", string.Empty, user.Identifier.ToString()); changeService.AddChange(user, "First Name", string.Empty, user.FirstName); changeService.AddChange(user, "Last Name", string.Empty, user.LastName); changeService.AddChange(user, "Email", string.Empty, user.Email); changeService.AddChange(user, "PasswordHash", string.Empty, user.PasswordHash); changeService.StoreChanges(); } return(accountCreated); }
public ActionResult Create([FromForm] UserAccountBuilder userAccountAttempt) { //if already logged in, redirect to account details if (LoggedInUser(out _)) { RedirectToAction("Details"); } if (ModelState.IsValid) { //pass the account to the service to validate and add it if (CreateNewAccount(userAccountAttempt)) { //direct user to login (new account created) return(RedirectToAction("AccountSuccess")); } } return(View()); }