Example #1
0
 public Joke GetByWebsiteId(int id)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.FirstOrDefault(p => p.Id == id));
     }
 }
Example #2
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();
            }
        }
Example #3
0
 public bool JokeInDb(int websiteId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Any(i => i.WebsiteId == websiteId));
     }
 }
Example #4
0
 public int GetJokeId(int websiteId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.FirstOrDefault(p => p.WebsiteId == websiteId).Id);
     }
 }
Example #5
0
 public IEnumerable <Joke> GetJokesForUser(int userId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Include(ul => ul.UserLikedJokes).Where(u => u.UserLikedJokes.Any(ui => ui.UserId == userId)).ToList());
     }
 }
Example #6
0
 public IEnumerable <UserLikedJokes> GetUserLikedJokes(int jokeId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.UserLikedJokes.Where(j => j.JokeId == jokeId).ToList());
     }
 }
Example #7
0
 public IEnumerable <Joke> GetJokes()
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Include(u => u.UserLikedJokes).ToList());
     }
 }
Example #8
0
 public bool DidUserLikeOrDislike(int userId, int jokeId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.UserLikedJokes.Any(u => u.UserId == userId && u.JokeId == jokeId));
     }
 }
Example #9
0
 public User GetByEmail(string email)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Example #10
0
 public void AddJoke(Joke joke)
 {
     using (var context = new JokesContext(_connectionString))
     {
         context.Jokes.Add(joke);
         context.SaveChanges();
     }
 }
Example #11
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();
            }
        }