public void AddLikeOrDislike(Jokes joke, Users user, bool liked) { UserLikedJokes ulj = GetLike(user.Id, joke.Id); using (var context = new JokesContext(_connectionString)) { var like = new UserLikedJokes { JokeId = joke.Id, UserId = user.Id, Liked = liked, Date = DateTime.Now }; if (ulj == null) { context.UserLikedJokes.Add(like); context.SaveChanges(); } else { context.UserLikedJokes.Attach(like); context.Entry(like).State = EntityState.Modified; context.SaveChanges(); } } }
public void AddJoke() { using (var context = new JokesContext(_connectionString)) { JokesApi jokesApi = new JokesApi(); Jokes joke = jokesApi.AddJoke(); joke.Id = 0; context.Jokes.Add(joke); context.SaveChanges(); } }