Exemplo n.º 1
0
 public UserJokeLike GetLike(int userId, int jokeId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.UserJokeLikes.FirstOrDefault(u => u.UserId == userId && u.JokeId == jokeId));
     }
 }
Exemplo n.º 2
0
 public IEnumerable <Joke> GetAll()
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Include(j => j.UserJokeLikes).ToList());
     }
 }
Exemplo n.º 3
0
 public Joke GetByOriginId(int originId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.FirstOrDefault(j => j.OriginId == originId));
     }
 }
Exemplo n.º 4
0
 public bool JokeExists(int originId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Any(j => j.OriginId == originId));
     }
 }
Exemplo n.º 5
0
 public User GetByEmail(string email)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Exemplo n.º 6
0
 public Joke GetWithLikes(int jokeId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Include(u => u.UserJokeLikes)
                .FirstOrDefault(j => j.Id == jokeId));
     }
 }
Exemplo n.º 7
0
 public void AddJoke(Joke joke)
 {
     using (var context = new JokesContext(_connectionString))
     {
         context.Jokes.Add(joke);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
        public void AddUser(User user, string password)
        {
            user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password);

            using (var context = new JokesContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void InteractWithJoke(int userId, int jokeId, bool like)
        {
            using (var context = new JokesContext(_connectionString))
            {
                var userLike = context.UserJokeLikes.FirstOrDefault(u => u.UserId == userId && u.JokeId == jokeId);
                if (userLike == null)
                {
                    context.UserJokeLikes.Add(new UserJokeLike
                    {
                        UserId = userId,
                        JokeId = jokeId,
                        Like   = like,
                        Date   = DateTime.Now
                    });
                }
                else
                {
                    userLike.Like = like;
                    userLike.Date = DateTime.Now;
                }

                context.SaveChanges();
            }
        }