コード例 #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));
     }
 }
コード例 #2
0
 public IEnumerable <Joke> GetAll()
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Include(j => j.UserJokeLikes).ToList());
     }
 }
コード例 #3
0
 public Joke GetByOriginId(int originId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.FirstOrDefault(j => j.OriginId == originId));
     }
 }
コード例 #4
0
 public bool JokeExists(int originId)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Jokes.Any(j => j.OriginId == originId));
     }
 }
コード例 #5
0
 public User GetByEmail(string email)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
コード例 #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));
     }
 }
コード例 #7
0
 public void AddJoke(Joke joke)
 {
     using (var context = new JokesContext(_connectionString))
     {
         context.Jokes.Add(joke);
         context.SaveChanges();
     }
 }
コード例 #8
0
        public void AddUser(User user, string password)
        {
            user.PasswordHash = PasswordHelper.HashPassword(password);

            using (var context = new JokesContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
コード例 #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();
            }
        }