Ejemplo n.º 1
0
        public void LikeDislikeJoke(int jokeId, int userId, bool status)
        {
            using (var context = new JokesContext(_connectionString))
            {
                var like = new UserLikedJokes
                {
                    UserId = userId,
                    JokeId = jokeId,
                    Liked  = status,
                    Date   = DateTime.Now
                };
                if (DidUserLikeOrDislike(userId, jokeId))
                {
                    context.Database.ExecuteSqlCommand(
                        "UPDATE UserLikedJokes SET Liked = @status WHERE UserId = @userId AND JokeId = @jokeId",
                        new SqlParameter("@status", status),
                        new SqlParameter("@userId", userId),
                        new SqlParameter("@jokeId", jokeId));
                }
                else
                {
                    context.UserLikedJokes.Add(like);
                }

                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public void AddJoke(Joke joke)
 {
     using (var context = new JokesContext(_connectionString))
     {
         context.Jokes.Add(joke);
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public void AddUser(User user, string password)
        {
            user.Password = PasswordEncryption.HashPassword(password);

            using (var context = new JokesContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }