Exemple #1
0
        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
        }
Exemple #2
0
        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();
        }
Exemple #3
0
 public static bool DoesExist(JokeDbContext _db, int id)
 {
     // returns the true if the jokeId exists in the database.
     return(_db.Jokes.Where(j => j.JokeId == id).Any());
 }
Exemple #4
0
 public static void addJoke(JokeDbContext _db, Joke newData)
 {
     _db.Jokes.Add(newData);
     _db.SaveChanges();
 }
Exemple #5
0
 /// <summary>
 /// Get all jokes by Category
 /// </summary>
 /// <param name="category">What category of the joke we are looking for</param>
 public static List <Joke> JokesByCategory(string category, JokeDbContext _db)
 {
     return((from j in _db.Jokes
             where j.Category == category
             select j).ToList());
 }
Exemple #6
0
 /// <summary>
 /// Retrieves all Jokes from the database.
 /// </summary>
 public static async Task <List <Joke> > GetAllJokes(JokeDbContext _db)
 {
     return(await _db.Jokes.ToListAsync());
 }