public void Seed(SubscribersDbContext db)
        {
            db.Database.Migrate();     // Run the migrations to update the database to latest version

            if (!db.Subscribers.Any()) // Seed the database with sample data only when empty (first time only)
            {
                // The sample data represents a set of subscribers with their names, emails and the subscribtion status
                db.Subscribers.AddRange(new List <Subscriber> {
                    new Subscriber {
                        Name = "Recipient", Email = "*****@*****.**", Subscribed = true
                    },
                    new Subscriber {
                        Name = "Recipient1", Email = "*****@*****.**", Subscribed = true
                    },
                    new Subscriber {
                        Name = "Recipient2", Email = "*****@*****.**", Subscribed = true
                    },
                    new Subscriber {
                        Name = "Recipient3", Email = "*****@*****.**", Subscribed = true
                    },
                    new Subscriber {
                        Name = "Recipient4", Email = "*****@*****.**", Subscribed = true
                    },
                    new Subscriber {
                        Name = "Recipient5", Email = "*****@*****.**", Subscribed = true
                    },
                    new Subscriber {
                        Name = "Recipient6", Email = "*****@*****.**", Subscribed = true
                    }
                });

                db.SaveChanges();
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SubscribersDbContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();

            Seed(db); // Seed the database with sample data
        }
Example #3
0
 public WebhooksController(SubscribersDbContext subscribersDb)
 {
     // Get instance for the DbContext from the DI
     _db = subscribersDb;
 }