public async Task RestoreUserAsync(string email) { var shroomsContext = _context as ShroomsDbContext; if (shroomsContext == null) { throw new ArgumentNullException(nameof(shroomsContext)); } await shroomsContext.Database .ExecuteSqlCommandAsync("UPDATE [dbo].[AspNetUsers] SET[IsDeleted] = '0' WHERE Email = @email", new SqlParameter("@email", email)); var user = await _userManager.FindByEmailAsync(email); await AddNewUserRolesAsync(user.Id); }
public async Task <IHttpActionResult> RegisterUser([FromBody] RegisterViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_administrationService.UserEmailExists(model.Email)) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null && !user.EmailConfirmed && _administrationService.HasExistingExternalLogin(model.Email, AuthenticationConstants.InternalLoginProvider)) { await _userManager.RemovePasswordAsync(user.Id); await _userManager.AddPasswordAsync(user.Id, model.Password); await _administrationService.SendUserVerificationEmail(user, RequestedOrganization); return(Ok()); } return(BadRequest("User already exists")); } if (_administrationService.UserIsSoftDeleted(model.Email)) { _administrationService.RestoreUser(model.Email); return(Ok()); } var result = await _administrationService.CreateNewUser(_mapper.Map <ApplicationUser>(model), model.Password, RequestedOrganization); if (!result.Succeeded) { return(GetErrorResult(result)); } return(Ok()); }