Ejemplo n.º 1
0
 public Joke GetByWebsiteId(int id)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.FirstOrDefault(p => p.Id == id));
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
0
 public bool JokeInDb(int websiteId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Any(i => i.WebsiteId == websiteId));
     }
 }
Ejemplo n.º 4
0
 public int GetJokeId(int websiteId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.FirstOrDefault(p => p.WebsiteId == websiteId).Id);
     }
 }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 6
0
 public IEnumerable <UserLikedJokes> GetUserLikedJokes(int jokeId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.UserLikedJokes.Where(j => j.JokeId == jokeId).ToList());
     }
 }
Ejemplo n.º 7
0
 public IEnumerable <Joke> GetJokes()
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Include(u => u.UserLikedJokes).ToList());
     }
 }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 9
0
 public User GetByEmail(string email)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Ejemplo n.º 10
0
 public void AddJoke(Joke joke)
 {
     using (var context = new JokesContext(_connectionString))
     {
         context.Jokes.Add(joke);
         context.SaveChanges();
     }
 }
Ejemplo n.º 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();
            }
        }