private void AddLike(int jokeId, int userId, bool liked) { using (var context = new JokesContext(_connectionString)) { var like = new UserLikedJoke { JokeId = jokeId, UserId = userId, Liked = liked, DateLiked = DateTime.Now }; context.UserLikedJokes.Add(like); context.SaveChanges(); } }
public void Like(int jokeId, int userId, bool liked) { using (var context = new JokesContext(_connectionString)) { UserLikedJoke likedjoke = context.UserLikedJokes.FirstOrDefault(ulj => ulj.JokeId == jokeId && ulj.UserId == userId); if (likedjoke == null) { AddLike(jokeId, userId, liked); } else { UpdateLike(jokeId, userId, liked); } } }