static int Main(string[] args)
        {
            using (var context = new WebShopContext())
            {
                context.Products.RemoveRange(context.Products);
                context.Prices.RemoveRange(context.Prices);
                context.Customers.RemoveRange(context.Customers);
                context.Orders.RemoveRange(context.Orders);

                // Product 1
                var price0 = new Price
                {
                    Id = 1,
                    FromDate = DateTime.Now,
                    Value = 100,
                    Currency = "DKK"
                };
                var product0 = new Product
                {
                    ProductNb = "p1",
                    Name = "Fancy Product",
                    Description = "This is a very fancy product."
                };
                product0.Prices.Add(price0);
                // Product 2
                var price1 = new Price
                {
                    Id = 2,
                    FromDate = DateTime.Parse("2015-10-12"),
                    Value = 499,
                    Currency = "DKK"
                };
                var price2 = new Price
                {
                    Id = 3,
                    FromDate = DateTime.Now,
                    Value = 399,
                    Currency = "DKK"
                };
                var product1 = new Product
                {
                    ProductNb = "p2",
                    Name = "Product on sale",
                    Description = "This product is currently on sale."
                };
                product1.Prices.Add(price1);
                product1.Prices.Add(price2);
                // Customer 1
                var customer0 = new Customer { Id = 1, FirstName = "Leslie", LastName = "McArthur", CurrentAddress = new Address("Lærkevang 23", "3, TH", "1234", "København", "", "Danmark") };
                // Order 1
                var order0 = new Order("DKK", customer0.CurrentAddress, customer0,
                    product0, product1);
                order0.Id = 1;

                context.Orders.Add(order0);
                context.SaveChanges();
            }

            return 0;
        }
Beispiel #2
0
        public Order(string currency, Address deliveryAddress, Customer customer, params Product[] products)
            : this()
        {
            OrderDateTime = DateTime.Now;
            Currency = currency;
            DeliveryAddress = deliveryAddress;
            Customer = customer;
            Customer.Orders.Add(this);

            // Add the products and increase the price.
            foreach (var p in products)
            {
                Products.Add(p);
                TotalPrice += p.GetCurrentPrice().Value;
            }

            Status = OrderStatus.Unshipped;
        }