Ejemplo n.º 1
0
        //public IEnumerable<Jokes> Get10Jokes()
        //{
        //    using (var ctx = new JokesContext(_connectionString))
        //    {
        //        return ctx.Jokes.Take(10);
        //    }
        //}
        //public IEnumerable<Jokes> AddTenJokes()
        //{
        //    var client = new JokesContext(_connectionString);
        //    var jokes = new List<Jokes>();
        //    for (int i = 0; i <= 10; i++)
        //    {
        //        jokes.Add(GetAPIJoke());
        //    }
        //    client.Jokes.AddRange(jokes.Where(i => GetJokeWithId(i.OriginId) == null));
        //    return jokes;

        //}

        #region LogIns
        public void AddUser(User user, string password)
        {
            string hash = BCrypt.Net.BCrypt.HashPassword(password);

            user.PasswordHash = hash;
            using (var context = new JokesContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public void AddLike(Jokes joke, User user)
 {
     using (var ctx = new JokesContext(_connectionString))
     {
         ctx.UserLikedJokes.Add(new UserLikedJokes
         {
             User      = user,
             UserId    = user.Id,
             DateLiked = DateTime.Now,
             Joke      = joke,
             JokeId    = joke.Id
         });
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public Jokes GetAPIJoke()
        {
            var   client = new HttpClient();
            var   result = JsonConvert.DeserializeObject <List <Jokes> >(client.GetStringAsync("https://official-joke-api.appspot.com/jokes/programming/random").Result);
            Jokes joke   = result.FirstOrDefault();

            using (var ctx = new JokesContext(_connectionString))
            {
                bool toAdd = GetJokeWithId(joke.OriginId) == null;
                if (toAdd)
                {
                    ctx.Jokes.Add(joke);
                    ctx.SaveChanges();
                }
            }
            return(joke);
        }
Ejemplo n.º 4
0
        private void AddTestData(JokesContext context)
        {
            var adminID = Guid.NewGuid();

            context.Users.Add(new User {
                ID = adminID, ModifiedBy = adminID, ModifiedDate = DateTime.UtcNow
            });
            context.JokeTypes.Add(new JokeType {
                ID = 1, IsActive = true, Value = "Dad Jokes"
            });
            context.JokeTypes.Add(new JokeType {
                ID = 2, IsActive = true, Value = "Funny Jokes"
            });
            context.JokeTypes.Add(new JokeType {
                ID = 3, IsActive = false, Value = "Blonde Jokes"
            });
            context.JokeTypes.Add(new JokeType {
                ID = 4, IsActive = true, Value = "Knock Knock Jokes"
            });
            context.JokeTypes.Add(new JokeType {
                ID = 5, IsActive = true, Value = "Food Jokes"
            });
            context.Jokes.Add(new Joke
            {
                ID           = Guid.Parse("4cb4e6a8-e7ba-42b9-b10b-f99e438dcc48"),
                JokeType_ID  = 3,
                Text         = @"A blonde, a redhead, and a brunette were all lost in the desert. 
                They found a lamp and rubbed it. A genie popped out and granted them each one wish. 
                The redhead wished to be back home. Poof! She was back home. The brunette wished to be at home with her family. 
                Poof! She was back home with her family. The blonde said, 'Awwww, I wish my friends were here.'",
                DislikeCount = 10,
                LikeCount    = 75,
                ModifiedBy   = adminID,
                ModifiedDate = DateTime.UtcNow
            });
            context.Jokes.Add(new Joke
            {
                ID           = Guid.Parse("ae8cc9d0-66c4-488e-9f32-81d36369ca37"),
                JokeType_ID  = 1,
                Text         = @"What time did the man go to the dentist? Tooth hurt-y.",
                DislikeCount = 956,
                LikeCount    = 233,
                ModifiedBy   = adminID,
                ModifiedDate = DateTime.UtcNow
            });
            context.Jokes.Add(new Joke
            {
                ID           = Guid.Parse("5a680e6e-7ebd-46a1-8127-e1557074f658"),
                JokeType_ID  = 2,
                Text         = @"The Teacher says to the class: Who ever stands up is stupid
                    *Nobody stands up*
                    Teacher: I said who ever stands up is STUPID!
                    *Little Johnny stands up*
                    Teacher: Johnny, do you really think that you are stupid?
                    Little Johnny: No Mrs, I just thought that maybe you are lonely being the only one standing.",
                DislikeCount = 99,
                LikeCount    = 199,
                ModifiedBy   = adminID,
                ModifiedDate = DateTime.UtcNow
            });
            context.Jokes.Add(new Joke
            {
                ID           = Guid.Parse("5e1a4248-ff96-443c-a68a-fc03a32addcc"),
                JokeType_ID  = 4,
                Text         = @"Knock knock. Who's there? Hawaii. Hawaii who? I'm fine, Hawaii you?",
                DislikeCount = 0,
                LikeCount    = 0,
                ModifiedBy   = adminID,
                ModifiedDate = DateTime.UtcNow
            });
            context.Jokes.Add(new Joke
            {
                ID           = Guid.Parse("6de160d4-40d4-4bac-a439-cac7ea16c8a0"),
                JokeType_ID  = 5,
                Text         = @"My friend thinks he is smart. He told me an onion is the only food that makes you cry, so I threw a coconut at his face.",
                DislikeCount = 12,
                LikeCount    = 22,
                ModifiedBy   = adminID,
                ModifiedDate = DateTime.UtcNow
            });
            context.SaveChanges();
            hasLoadedData = true;
        }