public void RegisterUser(RegisterUserInput registerUser) { var existingUser = _userRepository.FirstOrDefault(u => u.EmailAddress == registerUser.EmailAddress); if (existingUser != null) { if (!existingUser.IsEmailConfirmed) { SendConfirmationEmail(existingUser); throw new UserFriendlyException("You registere with this email address before (" + registerUser.EmailAddress + ")! We re-sent an activation code to your email!"); } throw new UserFriendlyException("There is already a user with this email address (" + registerUser.EmailAddress + ")! Select another email address!"); } var userEntity = registerUser.MapTo <TaskeverUser>(); userEntity.Password = new PasswordHasher().HashPassword(userEntity.Password); userEntity.GenerateEmailConfirmationCode(); _userRepository.Insert(userEntity); SendConfirmationEmail(userEntity); }