Пример #1
0
 public IEnumerable <Joke> GetAllJokes()
 {
     using (var ctx = new JokeContext(_connectionString))
     {
         return(ctx.Jokes.Include(j => j.Likes).ToList());
     }
 }
Пример #2
0
 public bool AlreadyLiked(Like like, bool liked)
 {
     using (var ctx = new JokeContext(_connectionString))
     {
         return(ctx.Likes.Any(l => l.UserId == like.UserId && l.JokeId == like.JokeId && l.Liked == liked));
     }
 }
Пример #3
0
 public Like GetLikeInfo(Like like)
 {
     using (var ctx = new JokeContext(_connectionString))
     {
         return(ctx.Likes.FirstOrDefault(l => l.UserId == like.UserId && l.JokeId == like.JokeId));
     }
 }
Пример #4
0
 public User GetUserByEmail(string email)
 {
     using (var context = new JokeContext(_connectionString))
     {
         return(context.Users.Include(u => u.Likes).FirstOrDefault(u => u.Email == email));
     }
 }
Пример #5
0
 private void AddJokeToDB(Joke joke)
 {
     using (var ctx = new JokeContext(_connectionString))
     {
         ctx.Jokes.Add(joke);
         ctx.SaveChanges();
     }
 }
Пример #6
0
 public void ChangeToLikeJoke(int jokeId, int userId)
 {
     using (var context = new JokeContext(_connectionString))
     {
         context.Database.ExecuteSqlCommand(
             "UPDATE Likes SET Liked = 'true' WHERE UserId = @userid AND JokeId = @jokeid",
             new SqlParameter("@userid", userId), new SqlParameter("@jokeid", jokeId));
     }
 }
Пример #7
0
 public void UpdateLike(Like like)
 {
     using (var ctx = new JokeContext(_connectionString))
     {
         ctx.Database.ExecuteSqlCommand(
             "UPDATE Likes SET Liked = @liked WHERE UserId = @id AND JokeId = @jokeid",
             new SqlParameter("@id", like.UserId), new SqlParameter("@jokeid", like.JokeId), new SqlParameter("@liked", like.Liked));
     }
 }
Пример #8
0
 public int AddUser(User user)
 {
     using (var context = new JokeContext(_connectionString))
     {
         user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);
         context.Users.Add(user);
         context.SaveChanges();
     }
     return(user.Id);
 }
Пример #9
0
 public bool LoginVerify(User user)
 {
     using (var context = new JokeContext(_connectionString))
     {
         User u      = GetUserByEmail(user.Email);
         bool verify = false;
         if (u != null)
         {
             verify = BCrypt.Net.BCrypt.Verify(user.Password, u.Password);
         }
         return(verify);
     }
 }
Пример #10
0
        //public bool AlreadyDisliked(Like like)
        //{
        //    using (var ctx = new JokeContext(_connectionString))
        //    {
        //        return ctx.Likes.Any(l => l.UserId == like.UserId && l.JokeId == like.JokeId && l.Liked == false);
        //    }
        //}

        public bool CanStillLike(Like like)
        {
            using (var context = new JokeContext(_connectionString))
            {
                Like li = context.Likes.FirstOrDefault(l => l.UserId == like.UserId && l.JokeId == like.JokeId);
                if (li != null)
                {
                    return(li.DateLiked.AddMinutes(5) > DateTime.Now);
                }
                else
                {
                    return(true);
                }
            }
        }
Пример #11
0
        public void LikeDislikeJoke(Like like)
        {
            using (var ctx = new JokeContext(_connectionString))
            {
                if (!ctx.Likes.Any(l => l.JokeId == like.JokeId && l.UserId == like.UserId))
                {
                    ctx.Likes.Add(new Like
                    {
                        UserId    = like.UserId,
                        JokeId    = like.JokeId,
                        DateLiked = DateTime.Now,
                        Liked     = like.Liked
                    });
                }

                UpdateLike(like);
                ctx.SaveChanges();
            }
        }