public static void DeleteLikedJoke(int jokeId) { var connection = LikeProvider.GetConnection(); using (var c = connection.CreateCommand()) { connection.Open(); c.CommandText = "DELETE from LikedJokes WHERE jokeid = " + jokeId; c.CommandType = CommandType.Text; c.ExecuteNonQuery(); } connection.Close(); }
public static long GetFilter() { long filtered = 0; var connection = LikeProvider.GetConnection(); using (var cmd = connection.CreateCommand()) { connection.Open(); cmd.CommandText = "SELECT Filtered FROM UserPreferences"; var read = cmd.ExecuteReader(); filtered = (Int64)read ["Filtered"]; connection.Close(); } return(filtered); }
public static void SaveLikedJoke(int jokeId) { var connection = LikeProvider.GetConnection(); using (var c = connection.CreateCommand()) { connection.Open(); //check if id already exists c.CommandText = "SELECT * FROM LikedJokes where JokeId = " + jokeId; if (c.ExecuteScalar() == null) { c.CommandText = "INSERT INTO LikedJokes (JokeId) VALUES (" + jokeId + ")"; c.CommandType = CommandType.Text; c.ExecuteNonQuery(); } } connection.Close(); }
public static int SetFilter(bool filtered) { int success = 1; var connection = LikeProvider.GetConnection(); int filter = filtered ? 1 : 0; try { using (var c = connection.CreateCommand()) { connection.Open(); c.CommandText = "UPDATE UserPreferences set Filtered = " + filter; c.CommandType = CommandType.Text; c.ExecuteNonQuery(); } } catch (Exception exc) { success = 0; } connection.Close(); return(success); }