public static void SeedDB(CustomerAppContext ctx)
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();
            var cust1 = ctx.Customers.Add(new Customer()
            {
                Address   = "BongiStreet",
                FirstName = "John",
                LastName  = "Olesen"
            }).Entity;

            var cust2 = ctx.Customers.Add(new Customer()
            {
                Address   = "BongiStreet 22",
                FirstName = "Bill",
                LastName  = "Bollesen"
            }).Entity;

            ctx.Orders.Add(new Order()
            {
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now,
                Customer     = cust1
            });
            ctx.Orders.Add(new Order()
            {
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now,
                Customer     = cust1
            });

            ctx.Orders.Add(new Order()
            {
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now,
                Customer     = cust2
            });

            ctx.SaveChanges();
        }
        public static void SeedDB(CustomerAppContext ctx)
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();
            var cust1 = ctx.Customers.Add(new Customer()
            {
                Address   = "BongiStreet",
                FirstName = "John",
                LastName  = "Olesen"
            }).Entity;

            var cust2 = ctx.Customers.Add(new Customer()
            {
                Address   = "BongiStreet 22",
                FirstName = "Bill",
                LastName  = "Bøllesen"
            }).Entity;

            var order1 = ctx.Orders.Add(new Order()
            {
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now,
                Customer     = cust1
            }).Entity;

            ctx.Orders.Add(new Order()
            {
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now,
                Customer     = cust1
            });
            ctx.Orders.Add(new Order()
            {
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now,
                Customer     = cust2
            });
            var prod = ctx.Products.Add(new Product()
            {
                Name = "smølf"
            }).Entity;

            ctx.Products.Add(new Product()
            {
                Name = "Ko"
            });
            ctx.OrderLines.Add(new OrderLine()
            {
                Product = prod,
                Order   = order1
            });

            var role1 = ctx.Roles.Add(new Role {
                Name = "Guest"
            }).Entity;

            ctx.Roles.Add(new Role {
                Name = "User"
            });
            var role3 = ctx.Roles.Add(new Role {
                Name = "Administrator"
            }).Entity;
            var role4 = ctx.Roles.Add(new Role {
                Name = "SuperAdministrator"
            }).Entity;

            ctx.Users.Add(
                new User()
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                PasswordHash = "AQAAAAEAACcQAAAAEFE8XWu6lIyinwsA4bBYJiOvabmOqZoURROPGY/eJdiNES+RGLLU7VW+/g3I+aFepA==",
                Role         = role1
            }
                );
            ctx.Users.Add(
                new User()
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                PasswordHash = "AQAAAAEAACcQAAAAENLKdwf9yrsIwY92GvwzYNVkXgdjoqWkgtt2TNlExnM+8lHORdurnPFszwiVYvJrwQ==",
                Role         = role3
            }
                );
            ctx.SaveChanges();
        }
Esempio n. 3
0
        public static void SeedDB(CustomerAppContext ctx)
        {
            //This ensures that the DB is deleted. before seeding
            //MAKE SURE TO BE UNDER THE SECTION "env.IsDevelopment()"
            //else it can delete complete production DB !!!DØD BABY!!!

            ctx.Database.EnsureDeleted();

            //Ensures the DB is created with the startup customers and orders
            //Seeds the Data into the DB - stacks with each startup
            ctx.Database.EnsureCreated();



            //Customers
            var cust1 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 1,
                FirstName = "Danni",
                LastName  = "Vase",
                Address   = "ShizzleStreet 123"
            }).Entity;
            var cust2 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                FirstName = "Bingo",
                LastName  = "Bango Bongo",
                Address   = "BishBashBosh 123"
            }).Entity;
            var cust3 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                FirstName = "Lars",
                LastName  = "Ulrich",
                Address   = "MetalSt. 112"
            }).Entity;
            var cust4 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                FirstName = "Flemming",
                LastName  = "Knudsen",
                Address   = "FlamingoSt. 321"
            }).Entity;
            var cust5 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                FirstName = "Winston",
                LastName  = "Churchill",
                Address   = "BritainSt. 232"
            }).Entity;
            var cust6 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                FirstName = "Bruce",
                LastName  = "Dickinson",
                Address   = "MaidenSt. 666"
            }).Entity;
            var cust7 = ctx.Customers.Add(new Customer()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                FirstName = "Adrian",
                LastName  = "Smith",
                Address   = "MaidenSt 1337"
            }).Entity;

            //Orders
            ctx.Orders.Add(new Order()
            {
                //ID Constraints with SQLite DB
                //Id = 1,
                OrderDate   = DateTime.Now,
                DeliverDate = DateTime.Now,
                Customer    = cust1
            });
            ctx.Orders.Add(new Order()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                OrderDate   = DateTime.Now,
                DeliverDate = DateTime.Now,
                Customer    = cust1
            });
            ctx.Orders.Add(new Order()
            {
                //ID Constraints with SQLite DB
                //Id = 2,
                OrderDate   = DateTime.Now,
                DeliverDate = DateTime.Now,
                Customer    = cust2
            });
            var admin = ctx.Users.Add(new User()
            {
                Username  = "******",
                Password  = "******",
                AccessLvl = 0
            });

            var user = ctx.Users.Add(new User()
            {
                Username  = "******",
                Password  = "******",
                AccessLvl = 5
            });

            ctx.SaveChanges();
        }