コード例 #1
0
 public User GetByEmail(string email)
 {
     using (var context = new JokesContext(_connectionString))
     {
         return(context.Users.Include(u => u.JokesLiked).ToList().Where(e => e.Email == email).First());
     }
 }
コード例 #2
0
 public IEnumerable <UserLikedJokes> GetUsersLikes(int userid)
 {
     using (var ctx = new JokesContext(_connectionString))
     {
         return(ctx.UserLikedJokes.Where(u => u.UserId == userid).ToList());
     }
 }
コード例 #3
0
 public IEnumerable <Jokes> GetAllJokes()
 {
     using (var ctx = new JokesContext(_connectionString))
     {
         return(ctx.Jokes.Include(j => j.UsersLiked).ToList());
     };
 }
コード例 #4
0
 public IEnumerable <UserLikedJokes> GetJokesLikes(int jokeId)
 {
     using (var ctx = new JokesContext(_connectionString))
     {
         return(ctx.UserLikedJokes.Where(j => j.JokeId == jokeId).ToList());
     }
 }
コード例 #5
0
 public RateJokeCommandHandler(
     JokesContext context,
     IQueryHandler <GetJokeByIdQuery, Joke> getJokeByIdQueryHandler)
 {
     _context = context;
     _getJokeByIdQueryHandler = getJokeByIdQueryHandler;
 }
コード例 #6
0
 public Jokes GetJokeWithId(int OriginId)
 {
     using (var ctx = new JokesContext(_connectionString))
     {
         Jokes j = ctx.Jokes.FirstOrDefault(t => t.OriginId == OriginId);
         return(j);
     }
 }
コード例 #7
0
 public PublishJokeCommandHandler(
     JokesContext context,
     IQueryHandler <GetFlagsByNamesQuery, IList <Flag> > getFlagsByNamesQuery,
     IQueryHandler <GetCategoriesByNamesQuery, IList <Category> > getCategoriesByNamesQuery)
 {
     _context = context;
     _getFlagsByNamesQuery      = getFlagsByNamesQuery;
     _getCategoriesByNamesQuery = getCategoriesByNamesQuery;
 }
コード例 #8
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();
            }
        }
コード例 #9
0
 public BaseController(IRepoFactory repoFactory, JokesContext context, IConfiguration config, IHttpContextAccessor httpContext, IMapper mapper)
 {
     if (!hasLoadedData)
     {
         AddTestData(context);
     }
     _repoFactory         = repoFactory;
     _repoFactory.Context = context;
     _config      = config;
     _httpContext = httpContext;
     _mapper      = mapper;
 }
コード例 #10
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();
     }
 }
コード例 #11
0
        private void InitContext()
        {
            var builder = new DbContextOptionsBuilder <JokesContext>()
                          .UseInMemoryDatabase(databaseName: "jokestestdb");

            var context = new JokesContext(builder.Options);

            var jokes = Enumerable.Range(1, 10)
                        .Select(i => new Joke {
                JokeId = i, JokeText = $"Joke{i}", JokeType = "general"
            });

            context.Jokes.AddRange(jokes);
            _jokesContext = context;
        }
コード例 #12
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);
        }
コード例 #13
0
 public GetJokeByIdQueryHandler(JokesContext context)
 {
     _context = context;
 }
コード例 #14
0
 public JokeController(IRepoFactory repoFactory, JokesContext context, IConfiguration config, IHttpContextAccessor httpContext, IMapper mapper)
     : base(repoFactory, context, config, httpContext, mapper)
 {
     _baseRepo = repoFactory.JokesRepo;
 }
コード例 #15
0
 public GetAllCategoriesQueryHandler(JokesContext context)
 {
     _context = context;
 }
コード例 #16
0
 public GetFilteredJokesQueryHandler(JokesContext context)
 {
     _context = context;
 }
コード例 #17
0
 public GetCategoriesByNamesQueryHandler(JokesContext context)
 {
     _context = context;
 }
コード例 #18
0
 public GetFlagsByNamesQueryHandler(JokesContext context)
 {
     _context = context;
 }
コード例 #19
0
 public BaseRepository(RepoFactory repoFactory)
 {
     this._RepoFactory = repoFactory;
     _context          = repoFactory._context;
 }
コード例 #20
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;
        }
コード例 #21
0
 public GetAllFlagsQueryHandler(JokesContext context)
 {
     _context = context;
 }