public async Task RegisterUserAsync(RegisterViewModel model) { var user = await _userRepo.GetUserByEmailAsync(model.Email); if (user != null) { throw new Exception("Użytkownik już istnieje w bazie"); } var salt = _encrypter.GetSalt(model.Password); var hash = _encrypter.GetHash(model.Password, salt); user = new User(Guid.NewGuid(), model.Email, hash, salt); await _userRepo.AddUserAsync(user); user.UserInRoles.Add(new UserInRole(user.UserId, model.Role.RoleId)); await _userInRoleRepo.SaveUserInRoles(user.UserInRoles); }