public async Task <UserGetModel> NewUser(UserPutModel newUser) { var user = new AppUser { Email = newUser.Email, UserName = newUser.Email, }; var result = await UserManager.CreateAsync(user, newUser.Password); if (!result.Succeeded) { return(null); } try { await UserManager.AddToRoleAsync(user, "Customer"); } catch (DbUpdateException) { } var roles = await UserManager.GetRolesAsync(user); var dto = new UserGetModel { Id = user.Id, CustomerId = user.CustomerId, UserName = user.UserName, Email = user.Email, Roles = roles }; return(dto); }
public async Task <bool> EditUser(UserPutModel updatedUser, string userId) { var user = await UserManager.FindByIdAsync(userId); if (user == null) { return(false); } user.Email = updatedUser.Email ?? user.Email; user.UserName = user.Email; try { await UserManager.UpdateAsync(user); } catch (DbUpdateConcurrencyException) { return(false); } if (!string.IsNullOrEmpty(updatedUser.Password)) { try { await UserManager.RemovePasswordAsync(_mapper.Map <AppUser>(user)); await UserManager.AddPasswordAsync(_mapper.Map <AppUser>(user), updatedUser.Password); } catch (DbUpdateConcurrencyException) { return(false); } } return(true); }
public void SetupUserPutModel() { userPutModel = new UserPutModel { Email = email, Password = password }; }
public async Task <bool> EditUser(UserPutModel updatedUser, string userId) { if (Succeeds) { Password = updatedUser.Password; Email = updatedUser.Email; UserName = updatedUser.Email; return(true); } return(false); }
public IActionResult PutUser(int id, UserPutModel model) { if (userService.UpdateItem(id, mapper.Map <UserPutModel, UserModel>(model))) { return(NoContent()); } else { return(NotFound()); } }
public async Task <IActionResult> PutUsers(int id, [FromBody] UserPutModel model) { if (model.RoleId.HasValue) { Roles _role = await _roleRepository.getRole(model.RoleId.Value); if (_role == null) { List <ValidationMessageModel> _validationMessages = new List <ValidationMessageModel>(); _validationMessages.Add(new ValidationMessageModel { Code = "RoleId", Key = "RoleId", Message = "RoleId Is Invalid" }); ProblemReporter.ReportBadRequest(JsonConvert.SerializeObject(_validationMessages)); } } Users _user = await _userRepository.GetUser(id); if (_user == null) { List <ValidationMessageModel> _validationMessages = new List <ValidationMessageModel>(); _validationMessages.Add(new ValidationMessageModel { Code = "Id", Key = "Id", Message = "Not Found" }); ProblemReporter.ReportResourseNotfound(JsonConvert.SerializeObject(_validationMessages)); } _user = _mapper.Map(model, _user); _user = await _userRepository.UpdateUser(_user); UserResponseModel _result = new UserResponseModel { Id = _user.Id, CreatedDate = _user.CreatedDate, Email = _user.Email, FirstName = _user.FirstName, LastName = _user.LastName, Phone = _user.Phone, Role = _user.Role.Role }; return(Ok(_result)); }
public async Task <UserGetModel> NewUser(UserPutModel newUser) { if (Succeeds) { Password = newUser.Password; return(new UserGetModel { CustomerId = DefaultCustomerId, Id = DefaultUserId, Email = newUser.Email, Roles = new List <string> { DefaultRole }, UserName = newUser.Email }); } return(null); }
public async Task <IHttpActionResult> Put(string id, UserPutModel user) //todo this not valid { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await _repo.UpdateUser(user, id); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } return(Ok()); }