예제 #1
0
        public bool SaveSession(JwtModel userJwt)
        {
            bool Ok = false;

            if (!_context.tblUserSessions.Any(e => e.UserID == userJwt.UserId &&
                                              e.SessionAttribute == userJwt.Token))
            {
                try
                {
                    var userID           = new SqlParameter("UserID", userJwt.UserId);
                    var sessionAttribute = new SqlParameter("SessionAttribute", userJwt.Token);

                    _context.Database.ExecuteSqlCommand("UserSessions_Insert @p0, @p1",
                                                        parameters: new[] { userJwt.UserId.ToString(),
                                                                            userJwt.Token });
                    _context.SaveChanges();

                    Ok = true;
                }
                catch (DbUpdateException ex)
                {
                    // TODO: Log file but don't worry for now
                    Ok = false;
                }
            }

            return(Ok);
        }
예제 #2
0
        private static VrsContext GetDBContext(string dbName)
        {
            var options = new DbContextOptionsBuilder <VrsContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;

            var context = new VrsContext(options);

            var lobs = Enumerable.Range(1, 10)
                       .Select(i => new tblLOBs {
                LOBID = i, LOB = $"Lob{i}"
            });

            context.tblLOBs.AddRange(lobs);

            int changed = context.SaveChanges();

            return(context);
        }
예제 #3
0
        public VrsContext GetContextWithData()
        {
            // http://gunnarpeipman.com/2017/04/aspnet-core-ef-inmemory/
            // https://mirkomaggioni.com/2017/07/01/in-memory-db-context-with-ef-core/
            // http://fiyazhasan.me/faking-with-in-memory-database-in-asp-net-core-2-0/
            // https://garywoodfine.com/entity-framework-core-memory-testing-database/
            // https://stormpath.com/blog/tutorial-entity-framework-core-in-memory-database-asp-net-core
            // http://blog.frankdecaire.com/category/entity-framework/

            //var options = new DbContextOptionsBuilder<VrsContext>()
            //                  .UseInMemoryDatabase(Guid.NewGuid().ToString())
            //                  .Options;
            //var context = new VrsContext(options);

            DbContextOptionsBuilder <VrsContext> builder = new DbContextOptionsBuilder <VrsContext>()
                                                           .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var context = new VrsContext(builder.Options);

            // _repository = new GamesRepository(_context);

            context.tblLOBs.Add(new tblLOBs {
                LOBID = 1, LOB = "VIC/ TAS"
            });
            context.tblLOBs.Add(new tblLOBs {
                LOBID = 2, LOB = "NSW/ ACT"
            });
            context.tblLOBs.Add(new tblLOBs {
                LOBID = 3, LOB = "QLD/ NT"
            });
            context.tblLOBs.Add(new tblLOBs {
                LOBID = 4, LOB = "WA"
            });
            context.tblLOBs.Add(new tblLOBs {
                LOBID = 5, LOB = "SA"
            });
            context.tblLOBs.Add(new tblLOBs {
                LOBID = 6, LOB = "NATIONAL"
            });
            context.tblLOBs.Add(new tblLOBs {
                LOBID = 10, LOB = "4 - LOB - NBN"
            });

            context.SaveChanges();

            //var beerCategory = new Category { Id = 1, Name = "Beers" };
            //var wineCategory = new Category { Id = 2, Name = "Wines" };
            //context.Categories.Add(beerCategory);
            //context.Categories.Add(wineCategory);

            //context.Products.Add(new Product { Id = 1, Name = "La Trappe Isid'or", Category = beerCategory });
            //context.Products.Add(new Product { Id = 2, Name = "St. Bernardus Abt 12", Category = beerCategory });
            //context.Products.Add(new Product { Id = 3, Name = "Zundert", Category = beerCategory });
            //context.Products.Add(new Product { Id = 4, Name = "La Trappe Blond", Category = beerCategory });
            //context.Products.Add(new Product { Id = 5, Name = "La Trappe Bock", Category = beerCategory });
            //context.Products.Add(new Product { Id = 6, Name = "St. Bernardus Tripel", Category = beerCategory });
            //context.Products.Add(new Product { Id = 7, Name = "Grottenbier Bruin", Category = beerCategory });
            //context.Products.Add(new Product { Id = 8, Name = "St. Bernardus Pater 6", Category = beerCategory });
            //context.Products.Add(new Product { Id = 9, Name = "La Trappe Quadrupel", Category = beerCategory });
            //context.Products.Add(new Product { Id = 10, Name = "Westvleteren 12", Category = beerCategory });
            //context.Products.Add(new Product { Id = 11, Name = "Leffe Bruin", Category = beerCategory });
            //context.Products.Add(new Product { Id = 12, Name = "Leffe Royale", Category = beerCategory });
            //context.SaveChanges();

            return(context);
        }