예제 #1
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<PromoContext>());

            Product rocketFuel = new Product { Name = "Rocket fuel", Price = 25.0m };
            Product doubleBlast = new Product { Name = "Double blast", Price = 40.0m };
            Product tripleBlast = new Product { Name = "Triple blast", Price = 40.0m };

            PromoContext dbContext = new PromoContext();

            IEnumerable<Product> products = dbContext.Products.ToArray();
            var asd = products.ToArray();
            //dbContext.Products.Add(rocketFuel);
            //dbContext.Products.Add(doubleBlast);
            dbContext.Products.Add(tripleBlast);

            Discount rocketFuelDiscount = new Discount { Product = rocketFuel, DiscountPolicy = new PromoDay { DayDate = DateTime.Today, DiscountPercentage = new Percentage(20) } };
            Client josephDeer = new Client
            {
                Name = "Joseph Deer",
                Address = "Czerwone Maki 84",
            };

            josephDeer.Offer(rocketFuelDiscount);
            Discount doubleBlastAccount = new Discount
            {
                Product = doubleBlast,
                DiscountPolicy =
                    new DiscountUntilExpired
                    {
                        DiscountPercentage = new Percentage(50),
                        FromTo = new DateSpan { StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(2) }
                    }
            };
            josephDeer.Offer(doubleBlastAccount);
            Client regularClient = new Client
            {
                Name = "Jack Ryan",
                Address = "Rynek 5"
            };

            dbContext.Clients.Add(regularClient);
            dbContext.Clients.Add(josephDeer);

            Discount discount = new Discount { Product = new Product { Name = "discounted product", Price = 12.0m } };
            dbContext.Discounts.Add(discount);
            dbContext.SaveChanges();
            int relatedProductId = discount.Product.Id;
            Discount insertedDiscount = dbContext.Discounts.Single(d => d.Id == discount.Id);
            dbContext.Discounts.Remove(insertedDiscount);
            dbContext.SaveChanges();
            Product releatedProduct = dbContext.Products.Single(p => p.Id == relatedProductId);
            insertedDiscount = dbContext.Discounts.Single(d => d.Id == discount.Id);
        }
예제 #2
0
        private static void DomainTest()
        {
            Product rocketFuel = new Product {Id = 1, Name = "Rocket fuel", Price = 25.0m};
            Product doubleBlast = new Product {Id = 2, Name = "Double blast", Price = 40.0m};
            Discount rocketFuelDiscount = new Discount
                {
                    Product = rocketFuel,
                    DiscountPolicy = new PromoDay {DayDate = DateTime.Today, DiscountPercentage = new Percentage(20)}
                };
            Client josephDeer = new Client
                {
                    Name = "Joseph Deer",
                    Address = "Czerwone Maki 84",
                };

            josephDeer.Offer(rocketFuelDiscount);
            Discount doubleBlastAccount = new Discount
                {
                    Product = doubleBlast,
                    DiscountPolicy =
                        new DiscountUntilExpired
                            {
                                DiscountPercentage = new Percentage(50),
                                FromTo = new DateSpan {StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(2)}
                            }
                };
            josephDeer.Offer(doubleBlastAccount);
            Client regularClient = new Client
                {
                    Name = "Jack Ryan",
                    Address = "Rynek 5"
                };


            decimal regularPrice = regularClient.GetPriceForThisClient(doubleBlast);
            decimal discountedPrice = josephDeer.GetPriceForThisClient(doubleBlast);
            Console.WriteLine("double Blast regular price ${0}, discounted price only ${1}!", regularPrice, discountedPrice);

            regularPrice = regularClient.GetPriceForThisClient(rocketFuel);
            discountedPrice = josephDeer.GetPriceForThisClient(rocketFuel);
            Console.WriteLine("rocket fuel regular price ${0}, discounted price only ${1}!", regularPrice, discountedPrice);

            Console.ReadKey();
        }