public bool Delete(DTOs.UserDTO DTOObj) //Deletes a specific user (based on email) { int res = -1; using (var connection = new SQLiteConnection(_connectionString)) { var command = new SQLiteCommand { Connection = connection, CommandText = $"DELETE FROM {_tableName} WHERE [{DTOs.UserDTO.UsersEmailColumn}]=@emailVal" }; command.Parameters.Add(new SQLiteParameter(@"emailVal", DTOObj.Email)); try { connection.Open(); res = command.ExecuteNonQuery(); } catch (Exception) { log.Debug("an error occured while updating this user."); } finally { command.Dispose(); connection.Close(); } } return(res > 0); }
public bool Insert(DTOs.UserDTO User) //creates a new User in the database. { using (var connection = new SQLiteConnection(_connectionString)) { var command = new SQLiteCommand(connection); int res = -1; try { connection.Open(); command.CommandText = $"INSERT INTO {_tableName} ({DTOs.UserDTO.UsersEmailColumn} ,{DTOs.UserDTO.UsersNicknameColumn},{DTOs.UserDTO.UsersPasswordColumn},{DTOs.UserDTO.UsersHostColumn}) " + $"VALUES (@emailVal,@nickNameVal,@passwordVal,@emailHostVal);"; command.Parameters.Add(new SQLiteParameter(@"emailVal", User.Email)); command.Parameters.Add(new SQLiteParameter(@"nickNameVal", User.Nickname)); command.Parameters.Add(new SQLiteParameter(@"passwordVal", User.Password)); command.Parameters.Add(new SQLiteParameter(@"emailHostVal", User.EmailHost)); command.Prepare(); res = command.ExecuteNonQuery(); } catch (Exception) { log.Debug("an error occured while creating this user."); } finally { command.Dispose(); connection.Close(); } return(res > 0); } }