public async Task <bool> UpdateUser(EditUserInfoVM updatedUser) { //Hämtar nuvarande användaren var currentUserId = userManager.GetUserId(contextAccessor.HttpContext.User); IdentityUser user = await userManager.FindByIdAsync(currentUserId); //Hämtar User för nuvarande användaren med AspId var userToUpdate = await context.User .SingleOrDefaultAsync(s => s.AspNetId == currentUserId); if (userToUpdate == null) { return(false); } try { userToUpdate.Firstname = updatedUser.Firstname; userToUpdate.Lastname = updatedUser.Lastname; userToUpdate.Street = updatedUser.Street; userToUpdate.City = updatedUser.City; userToUpdate.Zipcode = updatedUser.Zipcode; userToUpdate.Phonenumber = updatedUser.Phonenumber; await context.SaveChangesAsync(); return(true); } catch (DbUpdateException ex) { //TODO return(false); } }
public async Task <IActionResult> UpdateUserInfo(EditUserInfoVM edit) { if (!(await accountRepos.UpdateUser(edit))) { string msg = "Error!, we couldn't update user info"; return(RedirectToAction(nameof(Error), "User", msg)); } else { return(RedirectToAction(nameof(Index))); } }
public IActionResult UpdateUserInfo() { var user = accountRepos.GetCurrentUser(); var userToUpdate = new EditUserInfoVM { City = user.City, Firstname = user.Firstname, Lastname = user.Lastname, Phonenumber = user.Phonenumber, Street = user.Street, Zipcode = user.Zipcode, Username = user.Username }; return(View(userToUpdate)); }