Beispiel #1
0
        public static void EnsureDataSeeded(this ShoeEcommerceDBContext context)
        {
            var list = new List <Customer>()
            {
                new Customer()
                {
                    fstname = "Trần", lstname = "Tra", idCustomer = "1", phone = "0984518825",
                },
                new Customer()
                {
                    fstname = "Trần", lstname = "Tra", idCustomer = "2", phone = "0984518825"
                }
            };

            list.ForEach(p => context.Customers.Add(p));
            context.SaveChanges();
        }
Beispiel #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new ShoeEcommerceDBContext(
                       serviceProvider.GetRequiredService <DbContextOptions <ShoeEcommerceDBContext> >()))
            {
                if (!context.Merchants.Any())
                {
                    context.Merchants.AddRange(
                        new Merchant()
                    {
                        idMerchant = "noone",
                        fstname    = "test",
                        lstname    = "test",
                        phone      = "nonumber",
                        storename  = "nostore",
                        stt        = true
                    },
                        new Merchant()
                    {
                        idMerchant = "1",
                        fstname    = "adas",
                        lstname    = "acafc",
                        phone      = "01887762600",
                        storename  = "kynak",
                        stt        = true
                    }

                        );
                }
                context.SaveChanges();
                if (!context.Customers.Any())
                {
                    context.Customers.AddRange(
                        new Customer
                    {
                        idCustomer = "noone",
                        fstname    = "noname",
                        lstname    = "noname",
                        phone      = "none",
                        stt        = true
                    },
                        new Customer
                    {
                        idCustomer = "1",
                        fstname    = "Steve",
                        lstname    = "Myzus",
                        phone      = "090",
                        stt        = true
                    },
                        new Customer
                    {
                        idCustomer = "2",
                        lstname    = "Dog",
                        fstname    = "Thief",
                        phone      = "090",
                        stt        = true
                    },
                        new Customer
                    {
                        idCustomer = "3",
                        lstname    = "Cat",
                        fstname    = "Thief",
                        phone      = "090",
                        stt        = true
                    }
                        );
                }
                context.SaveChanges();
                var date = DateTime.Now;
                if (!context.Accounts.Any())
                {
                    context.Accounts.AddRange(

                        new Model.Accounts.Account()
                    {
                        idAccount   = "root",
                        username    = "******",
                        passwd      = "rootuser",
                        IdMerchant  = "noone",
                        rankVip     = "default",
                        rate        = 1,
                        idCustomer  = "noone",
                        avt_path    = "dasda",
                        CreatedDate = date,
                        stt         = true
                    },
                        new Model.Accounts.Account()
                    {
                        idAccount   = "1",
                        username    = "******",
                        passwd      = "passuser",
                        IdMerchant  = "noone",
                        rankVip     = "default",
                        rate        = 1,
                        idCustomer  = "1",
                        avt_path    = "dasda",
                        CreatedDate = date,
                        stt         = true
                    },
                        new Model.Accounts.Account()
                    {
                        idAccount   = "2",
                        username    = "******",
                        passwd      = "passuser",
                        IdMerchant  = "1",
                        rankVip     = "default",
                        rate        = 1,
                        idCustomer  = "noone",
                        avt_path    = "dasda",
                        CreatedDate = date,
                        stt         = true
                    });
                }
                context.SaveChanges();
                if (!context.RankVips.Any())
                {
                    context.RankVips.Add(new RankVip()
                    {
                        idRank   = "default",
                        viewRate = 15,
                        stt      = true
                    });
                }
                context.SaveChanges();
            }
        }