Beispiel #1
0
        static void Main(string[] args)
        {
            PeopleRepository repPeople = new PeopleRepository();
            ProductsRepository repProduct = new ProductsRepository();

            Console.WriteLine("People");
            Console.WriteLine("================================================================================");

            Console.WriteLine(repPeople.GetItem("Hunt").ToString());
            Console.WriteLine();

            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            repPeople.AddItem(new Person() { FirstName = "Zbigniew", LastName = "Koziel", Rating = 2, StartDate = DateTime.Now});
            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            repPeople.DeleteItem("Hunt");
            //repPeople.DeleteItem("Koziel"); //
            repPeople.DeleteItem("Koenig");
            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            Console.WriteLine(Convert.ToString(repPeople.GetItem("Koziel")));
            repPeople.UpdateItem("Koziel", new Person() { FirstName = "Zbigman", LastName = "Koziel", Rating = 9, StartDate = DateTime.Now });
            // Convert.ToString() doesn't throw exception if GetItem() returns null reference, in oppose to repPeople.GetItem().ToString()
            Console.WriteLine(Convert.ToString(repPeople.GetItem("Koziel")));
            Console.WriteLine();

            repPeople.UpdateItems(new List<Person>() {
                new Person(){ FirstName = "AAA", LastName = "aaa", StartDate = DateTime.Now, Rating = 1 },
                new Person(){ FirstName = "BBB", LastName = "bbb", StartDate = DateTime.Now, Rating = 1 },
                new Person(){ FirstName = "CCC", LastName = "ccc", StartDate = DateTime.Now, Rating = 1 },
                new Person(){ FirstName = "DDD", LastName = "ddd", StartDate = DateTime.Now, Rating = 1 },
            });
            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Products");
            Console.WriteLine("================================================================================");

            Console.WriteLine(repProduct.GetItem(3).ToString());
            Console.WriteLine();

            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            repProduct.AddItem(new Product() { ProductId = repProduct.GetItems().Max(p => p.ID) + 1, Category = "Instruments", ProductName = "Piano" });
            repProduct.AddItem(new Product() { ProductId = repProduct.GetItems().Max(p => p.ID) + 1, Category = "Instruments", ProductName = "Guitar" });
            repProduct.AddItem(new Product() { ProductId = repProduct.GetItems().Max(p => p.ID) + 1, Category = "Instruments", ProductName = "Fluet" });
            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            repProduct.DeleteItem(5);
            repProduct.DeleteItem(6);
            repProduct.DeleteItem(7);
            repProduct.DeleteItem(8);
            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            Console.WriteLine(Convert.ToString(repProduct.GetItem(1)));
            repProduct.UpdateItem(1, new Product() { ProductId = 1, Category = "Instruments", ProductName = "Clarinet" });
            Console.WriteLine(Convert.ToString(repProduct.GetItem(1)));
            Console.WriteLine();

            repProduct.UpdateItems(new List<Product>() {
                new Product(){ ProductId = 1, ProductName = "Lozko", Category = "Meble" },
                new Product(){ ProductId = 2, ProductName = "Suszarka", Category = "AGD" },
                new Product(){ ProductId = 3, ProductName = "Konfitury", Category = "Jedzenie" },
            });
            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            //Console.ReadKey();
        }