public void AddUser(UserDto userDto) { if (!UserNameIsUnique(userDto.UserName)) { throw new NonUniqueUserName(); } if (!UserValidation.ValidateUsername(userDto.UserName)) { throw new InvalidCharacters(); } using var connection = new SqliteConnection(_connectionString); var sql = "INSERT INTO User (UserName, Password, EmailAdress)" + " VALUES(@UserName, @Password, @EmailAdress)"; connection.Execute(sql, userDto); }
public void AddUser(UserDto userDto) { var id = _users.Count + 1; id = ValidateUniqueId(id); var user = new User(id, userDto.UserName, userDto.Password, userDto.EmailAdress); bool usernameOkay = UserValidation.ValidateUsername(userDto.UserName); if (!usernameOkay) { throw new InvalidCharacters(); } if (UserNameIsUnique(user)) { throw new NonUniqueUserName(); } if (_users.ContainsKey(user.UserId)) { throw new NonUniqueId(); } _users.Add(id, user); }