public User Post([FromBody] UserViewModel userViewModel) { userViewModel.Password = CommonHelper.Base64Encode(userViewModel.Password); var user = _userRepository.Add(userViewModel.Adapt <User>()); return(user); }
public async Task <IActionResult> Post([FromBody] UserViewModel viewModel) { if (viewModel == null) { return(new BadRequestResult()); } try { ApplicationUser user = await _userAndRoleRepository.GetUserByNameAsync(viewModel.UserName); if (user != null) { return(BadRequest("User with given username already exists")); } user = await _userAndRoleRepository.GetUserByEmailAsync(viewModel.Email); if (user != null) { return(BadRequest("User with given e-mail already exists")); } var createdUser = await _userAndRoleRepository.CreateUserAndAddToRolesAsync( viewModel.Adapt <ApplicationUser>(), new[] { UserRoles.RegisteredUser }); return(Json(createdUser.Adapt <UserViewModel>(), JsonSettings)); } catch (Exception e) { return(new StatusCodeResult(500)); } }
public async Task <UserViewModel> UpdateAsync(UserViewModel model) { var user = await _userRepository.GetByEmailAsync(model.Email); if (user is null) { return(null); } model.Adapt(user); return((await _userRepository.UpdateAsync(user)).Adapt <UserViewModel>()); }
public async Task UpdateProfile([FromBody] UserViewModel model) { var user = await GetCurrentUserAsync(); model.Id = user.Id; model.Email = user.Email; if (ModelState.IsValid) { model.Adapt(user); } await UserService.UpdateUserAsync(user); }
public async Task <ActionResult <User> > AddUser(UserViewModel input) { var user = input.Adapt <User>(); string userPassword = user.Password; if (string.IsNullOrEmpty(user.Password)) { //GENERATES PASSWORD userPassword = _accountsServices.CreatePassword(8); } //ENCRYPTS PASSWORD user.Password = Helpers.StringCipher.Encrypt(userPassword); user.IsFirstTimeLogin = true; _context.Users.Add(user); await _context.SaveChangesAsync(); try { //SEND WELCOME EMAIL WITH PASSWORD string to = user.Email, userID, password, SMTPPort, host; _emailServices.AppSettings(out userID, out password, out SMTPPort, out host); var url = this._configuration["webSiteUrl"]; string subject = "Thaniyas Farmer App Account Created"; string body = @"Welcome to Thaniyas Farmer App!<br /><br /> You have been added to the Thaniyas Farmer App system found here: " + url + @"<br /><br /> Please login with the below username and temporary password.<br /><br /> Username: "******"<br /> Password: "******"<br />"; _emailServices.SendEmail(subject, body, to, userID, password, SMTPPort, host); } catch (Exception ex) { } return(CreatedAtAction("GetUser", new { id = user.ID }, user)); }