public static void DeleteJoke(JokeDbContext _db, int jokeId) { Joke j = _db.Jokes.Find(jokeId); // find joke and start tracking _db.Jokes.Remove(j); // marks joke as deleted _db.SaveChanges(); // saves to database }
public static void UpdateJoke(JokeDbContext _db, int JokeId, string jokeText, string jokeCategory) { Joke j = _db.Jokes.Find(JokeId); _db.Jokes.Attach(j).State = EntityState.Modified; j.JokeText = jokeText; j.Category = jokeCategory; _db.SaveChanges(); }
public static void addJoke(JokeDbContext _db, Joke newData) { _db.Jokes.Add(newData); _db.SaveChanges(); }