public async Task <LoggedUserResponse> Registration(RegisterRequest registerRequest) { var base64Encode = PasswordHelper.EncodeAndHash(registerRequest.Password, out var passwordHash); var user = await CreateUser(registerRequest, passwordHash, base64Encode); await _appDbContext.SaveChangesAsync(CancellationToken.None); var token = JwtAuthManager.GenerateToken(user); return(LoggedUser(user, token)); }
public async Task <User> UpdateUserAsync(UserModel userModel) { var user = await _appDbContext.Users.SingleOrDefaultAsync(u => u.Id == userModel.Id); if (user == null) { return(null); } user.FirstName = userModel.FirstName; user.LastName = userModel.LastName; user.Email = userModel.Email; var base64EncodeFormat = _imageService.Base64FormatExists(userModel.SetImage); if (base64EncodeFormat) { var imageName = await _fileSystemService.UploadImage(userModel.SetImage); var image = await _imageService.SaveImage(imageName); user.ImageId = image.Id; } if (!string.IsNullOrEmpty(userModel.Password)) { var base64Encode = PasswordHelper.EncodeAndHash(userModel.Password, out var passwordHash); user.Password = passwordHash; user.PasswordSalt = base64Encode; } await _appDbContext.SaveChangesAsync(CancellationToken.None); var getUpdatedUser = GetUserAsync(userModel.Id); return(await getUpdatedUser); }