Пример #1
0
        public void Generate()
        {
            Customer previousCustomer = null;
            for (int i = 1; i < 10; i++)
            {
                var customer = new Customer
                {
                    Id = i,
                    Order = new Order
                    {
                        Id = i,
                        Choice = new ChoiceOrder
                        {
                            Id = i,
                            Ammount = i * 1000
                        }
                    },
                };

                if (i > 1)
                {
                    customer.Friend = previousCustomer;
                }

                _db.Customers.Add(customer);
                previousCustomer = customer;
            }

            _db.SaveChanges();
        }
        public void Generate()
        {
            Customer previousCustomer = null;
            for (int i = 1; i < 10; i++)
            {
                var customer = new Customer
                {
                    Id = i,
                    Order = new Order
                    {
                        Id = i,
                        Choice = new ChoiceOrder
                        {
                            Id = i,
                            Amount = i * 1000
                        }
                    },
                };

                if (i > 1)
                {
                    customer.Friend = previousCustomer;
                }

                // For customer whose id is 8 will have SpecialOrder with SpecialChoice.
                if (i == 8)
                {
                    customer.Order = new SpecialOrder
                    {
                        Id = i,
                        Choice = new ChoiceOrder
                        {
                            Id = i,
                            Amount = i * 1000
                        },
                        SpecialChoice = new ChoiceOrder()
                        {
                            Id = i * 100,
                            Amount = i * 2000
                        }
                    };
                }

                // For customer whose id is 9 will have VipOrder with SpecialChoice and VipChoice.
                if (i == 9)
                {
                    customer.Order = new VipOrder
                    {
                        Id = i,
                        Choice = new ChoiceOrder
                        {
                            Id = i,
                            Amount = i * 1000
                        },
                        SpecialChoice = new ChoiceOrder()
                        {
                            Id = i * 100,
                            Amount = i * 2000
                        },
                        VipChoice = new ChoiceOrder()
                        {
                            Id = i * 1000,
                            Amount = i * 3000
                        }
                    };
                }

                _db.Customers.Add(customer);
                previousCustomer = customer;
            }

            _db.SaveChanges();
        }