예제 #1
0
        static void Main(string[] args)
        {
            using (var context = new DatabaseContext())
            {
                ICustomerRepository customers = new CustomerRepository(context);
                IProductRepository products = new ProductRepository(context);

                var github = new Customer() { IsActive = true, Name = "GitHub" };
                var microsoft = new Customer() {IsActive = true, Name = "Microsoft"};
                var apple = new Customer() { IsActive = false, Name = "Apple" };

                customers.Create(github);
                customers.Create(microsoft);
                customers.Create(apple);

                var windows = new Product()
                {
                    CustomerId = microsoft.Id,
                    Description = "The best OS!",
                    Name = "Windows 10",
                    Sku = "AWESOME1"
                };

                var sourceControl = new Product()
                {
                    CustomerId = github.Id,
                    Description = "The best hosted source control solution!",
                    Name = "GitHub Enterprise",
                    Sku = "AWESOME2"
                };

                var iphone = new Product()
                {
                    CustomerId = apple.Id,
                    Description = "The best phone ever created!",
                    Name = "iPhone 6S",
                    Sku = "AWESOME3"
                };

                products.Create(windows);
                products.Create(sourceControl);
                products.Create(iphone);

                foreach (var customer in customers.All.WhereIsActive().ToList())
                {
                    Console.WriteLine(customer.Name);
                }

                foreach (var customer in customers.GetAllWithProducts().WhereNameBeginsWith("Git").WhereIsActive().ToList())
                {
                    Console.WriteLine(customer.Name);

                    foreach (var product in customer.Products)
                    {
                        Console.WriteLine("-- {0}", product.Name);
                    }
                }
            }
        }