Esempio n. 1
0
 public User GetByEmail(string email)
 {
     using (var context = new JokeContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
Esempio n. 2
0
 public Joke GetJokeWithLikes(int jokeId)
 {
     using (var cxt = new JokeContext(_connectionString))
     {
         return(cxt.Jokes
                .Include(j => j.UserLikedJokes)
                .FirstOrDefault(j => j.Id == jokeId));
     }
 }
Esempio n. 3
0
 public IEnumerable <Joke> GetJokes()
 {
     using (var cxt = new JokeContext(_connectionString))
     {
         return(cxt.Jokes
                .Include(j => j.UserLikedJokes)
                .ToList());
     }
 }
Esempio n. 4
0
        public void AddUser(User user, string password)
        {
            user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(password);

            using (var context = new JokeContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Esempio n. 5
0
 public void ChangeLikeStatusForJoke(Joke joke, int userId, bool liked)
 {
     using (var cxt = new JokeContext(_connectionString))
     {
         var result = cxt.Jokes.Where(j => j.Id == joke.Id).FirstOrDefault(j => j.UserId == userId);
         cxt.Database.ExecuteSqlCommand("UPDATE UserLikedJokes SET Liked = @liked WHERE JokeId = @jokeId And UserId = @userId",
                                        new SqlParameter("@liked", liked),
                                        new SqlParameter("@jokeId", result.Id),
                                        new SqlParameter("@userId", result.UserId));
     }
 }
Esempio n. 6
0
 public bool UserLikedJoke(int jokeId, int userId)
 {
     using (var cxt = new JokeContext(_connectionString))
     {
         var result = cxt.UserLikedJokes.FirstOrDefault(ulj => ulj.UserId == userId && ulj.JokeId == jokeId);
         if (result == null)
         {
             return(false);
         }
         return(true);
     }
 }
Esempio n. 7
0
 public void LikeJoke(Joke joke, int userId, bool liked)
 {
     using (var cxt = new JokeContext(_connectionString))
     {
         var ulj = new UserLikedJokes();
         ulj.JokeId    = joke.Id;
         ulj.UserId    = userId;
         ulj.Liked     = liked;
         ulj.DateLiked = DateTime.Now;
         cxt.UserLikedJokes.Add(ulj);
         if (!cxt.Jokes.Contains(joke))
         {
             cxt.Jokes.Add(joke);
         }
         cxt.SaveChanges();
     }
 }