public IActionResult Update(int id) { var user = _userRepository.GetOne(id); var model = new ApplicationUserUpdateViewModel(user); if (user == null) { new ArgumentException("id"); } return(View(model)); }
public IActionResult Update(ApplicationUserUpdateViewModel model) { var user = _userRepository.GetOne(model.Id); if (user == null) { new ArgumentException("id"); } user.ChangeFirstName(model.FirstName); user.ChangeLastName(model.LastName); user.ChangeEmail(model.Email); user.ChangePassword(model.Password); user.ChangeLanguage(model.Language); _userRepository.Update(user); return(RedirectToAction("Index")); }
public async Task <IActionResult> Update(ApplicationUserUpdateViewModel modelViewUser) { if (ModelState.IsValid) { ApplicationUser user = await _userManager.FindByIdAsync(modelViewUser.Id); if (user == null) { return(RedirectToAction("Index")); } user = AdaptApplicationUserFromUpdateViewModel(user, modelViewUser); var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction(nameof(Index))); } } return(View(modelViewUser)); }
public async Task <IActionResult> Update(string id) { ApplicationUser user = await _userManager.FindByIdAsync(id); if (user == null) { return(RedirectToAction("Index")); } ApplicationUserUpdateViewModel updatedUser = new ApplicationUserUpdateViewModel(); updatedUser.Id = user.Id; updatedUser.Name = user.UserName; updatedUser.Surname = user.Surname; updatedUser.Email = user.Email; updatedUser.LinkedIn = user.LinkedIn; updatedUser.DNI = user.DNI; updatedUser.Phone = user.Phone; updatedUser.City = user.City; updatedUser.Country = user.Country; return(View(updatedUser)); }
public async Task <ActionResult> Update(Guid id, ApplicationUserUpdateViewModel model) { if (!ModelState.IsValid) { return(JsonResultEx.Create(ModelState)); } // create role if not exists model.Roles = (model.Roles ?? new List <string>()).Distinct(); var roles = await _membershipService.GetRoles().Select(x => x.Name).ToListAsync().ConfigureAwait(false); foreach (var role in model.Roles) { if (!roles.Contains(role)) { await _membershipService.CreateRole(role); } } var applicationUserUpdateOptions = _mapping.Map <ApplicationUserUpdateOptions>(model, options => options.Items.Add(nameof(id), id)); var result = await _membershipService.UpdateUser(applicationUserUpdateOptions).ConfigureAwait(false); return(JsonResultEx.Create(result)); }
private ApplicationUser AdaptApplicationUserFromUpdateViewModel(ApplicationUser user, ApplicationUserUpdateViewModel modelViewUser) { user.Id = modelViewUser.Id; user.Name = modelViewUser.Name; user.UserName = modelViewUser.Name; user.Surname = modelViewUser.Surname; user.Email = modelViewUser.Email; user.LinkedIn = modelViewUser.LinkedIn; user.DNI = modelViewUser.DNI; user.Phone = modelViewUser.Phone; user.City = modelViewUser.City; user.Country = modelViewUser.Country; user.EntryDate = DateTime.Now; return(user); }