//users public void AddUser(User user) { using (var ctx = new JokesContext(_connString)) { ctx.Users.Add(user); ctx.SaveChanges(); } }
//jokes private void AddJoke(Joke joke) { using (var ctx = new JokesContext(_connString)) { IEnumerable <Joke> jokes = ctx.Jokes; if (!jokes.Any(j => j.Id == joke.Id)) { ctx.Jokes.Add(joke); ctx.SaveChanges(); } } }
public void LikeJoke(int jokeId, string userName, bool like) { User user = GetUserByEmail(userName); using (var ctx = new JokesContext(_connString)) { if (ctx.UsersLikedJokes.Any(l => l.JokeId == jokeId && l.UserId == user.Id)) { UpdateLike(jokeId, user.Id, like); } else { UsersLikedJokes ulj = new UsersLikedJokes { JokeId = jokeId, Liked = like, Date = DateTime.Now, UserId = user.Id }; ctx.UsersLikedJokes.Add(ulj); ctx.SaveChanges(); } } }