Example #1
0
        private static void PopulateProducts(SportsStoreDbContext db)
        {
            if (db.Products.Any())
            {
                return;
            }

            db.Products.AddRange(
                new Product {
                Name = "Kayak", Description = "A boat", Category = "WaterSports", Price = 55
            },
                new Product {
                Name = "Ola", Description = "Adeus", Category = "Categs", Price = 69
            },
                new Product {
                Name = "Adeus", Description = "A booty", Category = "WaterSports", Price = 455
            },
                new Product {
                Name = "Olas", Description = "sdfsdf", Category = "Categs", Price = 649
            },
                new Product {
                Name = "Olas1", Description = "sdfsdfssss", Category = "Categs1", Price = 649
            },
                new Product {
                Name = "Olas2", Description = "sdfsdfddd", Category = "Categs2", Price = 6419
            },
                new Product {
                Name = "Olas3", Description = "sdfsdfee", Category = "Categs3", Price = 6492
            },
                new Product {
                Name = "Olas4", Description = "sdfsdfaaa", Category = "Categs4", Price = 6493
            },
                new Product {
                Name = "Olas5", Description = "sdfsdfdfs", Category = "Categs5", Price = 6494
            },
                new Product {
                Name = "Olas6", Description = "sdfsdfssdd", Category = "Categs6", Price = 6495
            },
                new Product {
                Name = "Olas7", Description = "sdfsdfaadd", Category = "Categs7", Price = 6496
            }
                );

            db.SaveChanges();
        }
Example #2
0
 public static void Populate(SportsStoreDbContext db)
 {
     PopulateProducts(db);
 }
Example #3
0
 public EFSportsStoreRepository(SportsStoreDbContext db)
 {
     this.db = db;
 }
Example #4
0
 public EntityFrameWorkRepository(SportsStoreDbContext context)
 {
     this.context = context;
 }
Example #5
0
 public EFOrderRepository(SportsStoreDbContext context)
 {
     this.context = context;
 }
Example #6
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            SportsStoreDbContext context = app
                                           .ApplicationServices
                                           .CreateScope()
                                           .ServiceProvider
                                           .GetRequiredService <SportsStoreDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (context.Products.Any())
            {
                return;
            }

            context.Products.AddRange(
                new Product
            {
                Name        = "Kayak",
                Description = "A boat for one person",
                Category    = "Watersports",
                Price       = 275
            },
                new Product
            {
                Name        = "Lifejacket",
                Description = "Protective and fashionable",
                Category    = "Watersports",
                Price       = 48.95m
            },
                new Product
            {
                Name        = "Soccer Ball",
                Description = "FIFA-approved size and weight",
                Category    = "Soccer",
                Price       = 19.50m
            },
                new Product
            {
                Name        = "Corner Flags",
                Description = "Give your playing field a professional touch",
                Category    = "Soccer",
                Price       = 34.95m
            },
                new Product
            {
                Name        = "Stadium",
                Description = "Flat-packed 35,000-seat stadium",
                Category    = "Soccer",
                Price       = 79500
            },
                new Product
            {
                Name        = "Thinking Cap",
                Description = "Improve brain efficiency by 75%",
                Category    = "Chess",
                Price       = 16
            },
                new Product
            {
                Name        = "Unsteady Chair",
                Description = "Secretly give your opponent a disadvantage",
                Category    = "Chess",
                Price       = 29.95m
            },
                new Product
            {
                Name        = "Human Chess Board",
                Description = "A fun game for the family",
                Category    = "Chess",
                Price       = 75
            },
                new Product
            {
                Name        = "Bling-Bling King",
                Description = "Gold-plated, diamond-studded King",
                Category    = "Chess",
                Price       = 1200
            }
                );

            context.SaveChanges();
        }