public async Task <IActionResult> EditAccount([FromForm] AdminEditAccountViewModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var user_identity = await _userManager.FindByIdAsync(model.UserId); user_identity.Email = model.Email; user_identity.UserName = model.Username; var result = await _userManager.UpdateAsync(user_identity); Guid adminIdGuid = Guid.Empty; if (!Guid.TryParse(model.UserId, out adminIdGuid)) { throw new Exception("Invalid Guid Format"); } adminsService.EditAccount(adminIdGuid, model.FirstName, model.LastName); return(Redirect(Url.Action("Index", "Admins"))); }
public async Task <IActionResult> EditAccount() { var userId = _userManager.GetUserId(User); var user_identity = await _userManager.FindByIdAsync(userId); var user_email = await _userManager.GetEmailAsync(user_identity); var user_username = await _userManager.GetUserNameAsync(user_identity); var admin = adminsService.GetAdminById(userId); AdminEditAccountViewModel adminEditAccountViewModel = new AdminEditAccountViewModel { UserId = userId, FirstName = admin.FirstName, LastName = admin.LastName, Email = user_email, Username = user_username }; return(View(adminEditAccountViewModel)); }