Ejemplo n.º 1
0
 public Joke GenerateRandomJoke()
 {
     using (var context = new JokesContext(_conn))
     {
         var    client = new HttpClient();
         string url    = "https://official-joke-api.appspot.com/jokes/programming/random";
         string json   = client.GetStringAsync(url).Result;
         var    result = JsonConvert.DeserializeObject <IEnumerable <Joke> >(json).First();
         context.Jokes.Add(result);
         context.SaveChanges();
         return(result);
     }
 }
Ejemplo n.º 2
0
 public void AddUser(User u)
 {
     using (var context = new JokesContext(_conn))
     {
         var user = new User
         {
             Name     = u.Name,
             Email    = u.Email,
             Password = HashPassword(u.Password)
         };
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void DislikeJoke(int userId, int jokeId)
 {
     using (var context = new JokesContext(_conn))
     {
         if (context.UserLikedJokes.Any(l => l.UserId == userId && l.JokeId == jokeId))
         {
             UpdateLike(userId, jokeId, false);
         }
         else
         {
             context.UserLikedJokes.Add(new UserLikedJokes
             {
                 UserId = userId,
                 JokeId = jokeId,
                 //Liked = false,
                 Time = DateTime.Now
             });
             //UpdateLike(userId, jokeId, false);
             context.SaveChanges();
             UpdateLike(userId, jokeId, false);
         }
     }
 }