public static void SeedDB(PetShopAppContext ctx)
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();
            var owner1 = ctx.Owners.Add(new Owner()
            {
                FirstName   = "Tina",
                LastName    = "´Jønsson",
                Address     = "DinMorVej 22",
                Email       = "*****@*****.**",
                PhoneNumber = "6969696969"
            }).Entity;

            var owner2 = ctx.Owners.Add(new Owner()
            {
                FirstName   = "Jesper",
                LastName    = "Riis",
                Address     = "DinFarVej 69",
                Email       = "*****@*****.**",
                PhoneNumber = "9696969696"
            }).Entity;

            var pet1 = ctx.Pets.Add(new Pet()
            {
                Name          = "Rogue",
                Type          = "Cat",
                Birthdate     = new DateTime(2014, 07, 31),
                SoldDate      = new DateTime(2017, 03, 21),
                Color         = "Cream",
                PreviousOwner = owner1,
                Price         = 25,
            }).Entity;

            var pet2 = ctx.Pets.Add(new Pet()
            {
                Name          = "Leo",
                Type          = "Løve",
                Birthdate     = new DateTime(2014, 07, 31),
                SoldDate      = new DateTime(2017, 03, 21),
                Color         = "Lyserød",
                PreviousOwner = owner2,
                Price         = 343423,
            }).Entity;

            string password = "******";

            byte[] passwordHashUser, passwordSaltUser, passwordHashAdmin, passwordSaltAdmin;
            CreatePasswordHash(password, out passwordHashUser, out passwordSaltUser);
            CreatePasswordHash(password, out passwordHashAdmin, out passwordSaltAdmin);

            List <User> users = new List <User>
            {
                new User {
                    UserName     = "******",
                    PasswordHash = passwordHashUser,
                    PasswordSalt = passwordSaltUser,
                    IsAdmin      = false
                },
                new User {
                    UserName     = "******",
                    PasswordHash = passwordHashAdmin,
                    PasswordSalt = passwordSaltAdmin,
                    IsAdmin      = true
                }
            };

            ctx.AddRange(users);
            ctx.SaveChanges();
        }
        public static void DbSeed(PetShopAppContext ctx, IAuthenticationService authenticationService)
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();
            var petType = new PetType
            {
                Type = "Khar"
            };

            ctx.PetTypes.Add(petType);

            var owner = new Owner
            {
                FirstName = "Reza",
                Email     = "*****@*****.**",
            };

            ctx.Owners.Add(owner);
            ctx.SaveChanges();
            var pet1 = ctx.pets.Add(new Pet()
            {
                Color     = "Black",
                Name      = "SomeName",
                OwnerId   = owner.Id,
                Birthdate = DateTime.Now.AddMonths(-12),
                price     = 1200,
                petTypeId = petType.Id,
            }).Entity;

            ctx.pets.Add(new Pet()
            {
                Color     = "Black",
                Name      = "SomeName",
                OwnerId   = owner.Id,
                Birthdate = DateTime.Now.AddMonths(-12),
                price     = 1200,
                petTypeId = petType.Id,
            });
            ctx.SaveChanges();

            string password = "******";

            byte[] passwordHashJoe, passwordSaltJoe, passwordHashAnn, passwordSaltAnn;
            authenticationService.CreatePasswordHash(password, out passwordHashJoe, out passwordSaltJoe);
            authenticationService.CreatePasswordHash(password, out passwordHashAnn, out passwordSaltAnn);
            List <User> users = new List <User>
            {
                new User {
                    Username     = "******",
                    PasswordHash = passwordHashJoe,
                    PasswordSalt = passwordSaltJoe,
                    IsAdmin      = false
                },
                new User {
                    Username     = "******",
                    PasswordHash = passwordHashAnn,
                    PasswordSalt = passwordSaltAnn,
                    IsAdmin      = true
                }
            };

            ctx.Users.AddRange(users);
            ctx.SaveChanges();
        }
        public static void SeedDB(PetShopAppContext ctx)
        {
            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();

            string password = "******";

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);
            Console.WriteLine();

            Owner owner1 = new Owner
            {
                FirstName    = "Dave",
                LastName     = "McColgan",
                Address      = "93 Mendota Road",
                Email        = "*****@*****.**",
                PhoneNumber  = "52467277",
                Username     = "******",
                IsAdmin      = true,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt
            };

            Owner owner2 = new Owner
            {
                FirstName    = "Munroe",
                LastName     = "Wardlaw",
                Address      = "6 Commercial Lane",
                Email        = "*****@*****.**",
                PhoneNumber  = "53595277",
                Username     = "******",
                IsAdmin      = false,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt
            };



            Owner owner3 = ctx.Owners.Add(new Owner
            {
                FirstName   = "James",
                LastName    = "McAdams",
                Address     = "11 Daytona Road",
                Email       = "*****@*****.**",
                PhoneNumber = "4550798879"
            }).Entity;

            Owner owner4 = ctx.Owners.Add(new Owner
            {
                FirstName   = "Jose",
                LastName    = "Murdan",
                Address     = "7 Fakey Street",
                Email       = "*****@*****.**",
                PhoneNumber = "57972647"
            }).Entity;

            Pet pet1 = new Pet
            {
                Name     = "Don",
                Type     = "dog",
                BirthDay = DateTime.Now.AddMonths(-5),
                SoldDate = DateTime.Now,
                Color    = "Black",
                owner    = owner1,
                Price    = 110.2
            };

            Pet pet2 = new Pet
            {
                Name     = "James",
                Type     = "cat",
                BirthDay = DateTime.Now.AddYears(-2),
                SoldDate = DateTime.Now,
                Color    = "Cream",
                owner    = owner1,
                Price    = 398.8
            };

            Pet pet3 = new Pet
            {
                Name     = "Ping",
                Type     = "duck",
                BirthDay = DateTime.Now.AddYears(-7),
                SoldDate = DateTime.Now.AddYears(-5).AddMonths(-3),
                Color    = "Brown",
                owner    = owner2,
                Price    = 487.5
            };

            Pet pet4 = new Pet
            {
                Name     = "Mandel",
                Type     = "spider",
                BirthDay = DateTime.Now.AddYears(-1),
                SoldDate = DateTime.Now.AddMonths(-9),
                Color    = "Black",
                owner    = owner2,
                Price    = 499.9
            };

            Pet pet5 = new Pet
            {
                Name     = "Lessie",
                Type     = "dog",
                BirthDay = DateTime.Now.AddYears(-5),
                SoldDate = DateTime.Now.AddYears(-4).AddMonths(-9),
                Color    = "Whitish brown",
                owner    = owner2,
                Price    = 624.36
            };


            Pet pet6 = new Pet
            {
                Name     = "fishyMisi",
                Type     = "Fish",
                BirthDay = DateTime.Now.AddYears(-12),
                SoldDate = DateTime.Now.AddMonths(-96),
                Color    = "fos",
                owner    = null,
                Price    = 14.9
            };

            ctx.Pets.Add(pet1);
            ctx.Pets.Add(pet2);
            ctx.Pets.Add(pet3);
            ctx.Pets.Add(pet4);
            ctx.Pets.Add(pet5);
            ctx.Pets.Add(pet6);
            ctx.Owners.Add(owner1);
            ctx.Owners.Add(owner2);
            ctx.Owners.Add(owner3);
            ctx.Owners.Add(owner4);
            ctx.SaveChanges();
        }
Exemple #4
0
 public UserRepository(PetShopAppContext ctx)
 {
     _ctx = ctx;
 }