public async Task <IActionResult> Edit(string id) { var res = await _userManagerService.GetUserById(id); if (res == null) { return(NotFound()); } EditAccountUserViewModel model = new EditAccountUserViewModel { Id = res.Id, Name = res.Name, PhoneNumber = res.PhoneNumber, Adress = res.Adress, Description = res.Description }; return(View(model)); }
public async Task <IActionResult> Edit(EditAccountUserViewModel model) { if (ModelState.IsValid) { var account = await _userManagerService.GetUserById(model.Id); if (account != null) { if (model.AccountImg != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(model.AccountImg.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.AccountImg.Length); } account.Name = model.Name; account.PhoneNumber = model.PhoneNumber; account.Adress = model.Adress; account.Description = model.Description; account.AccountImg = imageData; var result = await _userManagerService.UpdateAccount(account); if (result.Succeeded) { _commitProvider.Save(); return(RedirectToAction("Index")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } } } return(View(model)); }