Esempio n. 1
0
        static void Main(string[] args)
        {
            GenericDb <Shape> .Shapes.Add(new Circle()
            {
                Id = 5, Radius = 2
            });

            GenericDb <Shape> .Shapes.Add(new Rectangle()
            {
                Id = 6, SideA = 1.5, SideB = 2.8
            });

            foreach (Shape shape in GenericDb <Shape> .Shapes)
            {
                shape.PrintInfo();
            }

            Console.WriteLine("\nAREAS : \n");
            GenericDb <Shape> .PrintArea();

            Console.WriteLine("\nPERIMETERS :\n ");
            GenericDb <Shape> .PrintPerimeter();


            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GenericDb <Shape> .Shapes.Add(new Circle()
            {
                Id = 1, Radius = 3
            });

            GenericDb <Shape> .Shapes.Add(new Rectangle()
            {
                Id = 2, SideA = 2, SideB = 2.5
            });

            Console.WriteLine("Area of the shapes:");
            GenericDb <Shape> .PrintAreas();

            Console.WriteLine("Perimeter of the shapes:");
            GenericDb <Shape> .PrintPerimeters();


            Shape circle = GenericDb <Shape> .Shapes[0];

            circle.PrintInfo();

            Shape rectangle = GenericDb <Shape> .Shapes[1];

            rectangle.PrintInfo();

            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Dog  dog1  = new Dog("Sparky", AnimalType.Dog, 3, "steak");
            Dog  dog2  = new Dog("Lily", AnimalType.Dog, 2, "steak");
            Cat  cat1  = new Cat("Tom", AnimalType.Cat, 4, true, 4);
            Cat  cat2  = new Cat("Lucy", AnimalType.Cat, 2, false, 4);
            Fish fish1 = new Fish("Bobby", AnimalType.Fish, 1, "Red", "Medium");
            Fish fish2 = new Fish("Jenny", AnimalType.Fish, 4, "Blue", "Big");

            GenericDb <Dog> .AddPetToList(dog1);

            GenericDb <Dog> .AddPetToList(dog2);

            GenericDb <Cat> .AddPetToList(cat1);

            GenericDb <Cat> .AddPetToList(cat2);

            GenericDb <Fish> .AddPetToList(fish1);

            GenericDb <Fish> .AddPetToList(fish2);

            GenericDb <Dog> .PrintPets(GenericDb <Dog> .Pets);

            GenericDb <Cat> .PrintPets(GenericDb <Cat> .Pets);

            GenericDb <Fish> .PrintPets(GenericDb <Fish> .Pets);

            GenericDb <Cat> .BuyPet(GenericDb <Cat> .Pets, "Sparky");

            GenericDb <Cat> .BuyPet(GenericDb <Cat> .Pets, "Tom");

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

            GenericDb <Cat> .BuyPet(CatStore.Cats, "Tom");

            GenericDb <Cat> .BuyPet(CatStore.Cats, "Tommy");

            GenericDb <Dog> .BuyPet(DogStore.Dogs, "Tony");

            GenericDb <Dog> .BuyPet(DogStore.Dogs, "Jill");

            GenericDb <Dog> .PrintPets(DogStore.Dogs);

            GenericDb <Cat> .PrintPets(CatStore.Cats);

            GenericDb <Fish> .PrintPets(FishStore.Fish);

            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            GenericDb <Employee> employeeDb = new GenericDb <Employee>(); // Employee is the type that will be passed in "T" parameter

            employeeDb.Create(new Employee {
                Id = 1, FirstName = "Alek", LastName = "Kocevski"
            });                                                                                    // Since we already created an object from GenericDb and passed a Type(Employee), the Create() method now takes 1 parameter of type Employee.
            employeeDb.Create(new Employee {
                Id = 2, FirstName = "Dejan", LastName = "Blazheski"
            });
            employeeDb.Create(new Employee {
                Id = 3, FirstName = "Ivica", LastName = "Janveski"
            });

            Employee employee = employeeDb.Read(1);


            GenericDb <Product> productDb = new GenericDb <Product>(); // In this case Product will be the type that will be passed in "T" parameter

            productDb.Create(new Product {
                Id = 1, Name = "Stobi Flips", Brand = "Vitaminka"
            });
            productDb.Create(new Product {
                Id = 2, Name = "Choicko Stobi Flips", Brand = "Vitaminka"
            });

            Product product = productDb.Read(2);


            //GenericDb<string> stringDb = new GenericDb<string>(); // We cannot create a GenericDb of type strings, since we added a restriction for the types, the type must inherit from IBaseEntity and string does NOT.
            //stringDb.Create("String that should not be in a database");



            Console.WriteLine(employee.FirstName);
            Console.WriteLine(product.Name);

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Apple apple1 = new Apple {
                Taste = "Sweet", VitaminsAmount = 20
            };
            Apple apple2 = new Apple {
                Taste = "Sweet", VitaminsAmount = 19
            };
            Apple apple3 = new Apple {
                Taste = "Sweet", VitaminsAmount = 21
            };
            Orange orange1 = new Orange {
                Taste = "Sweet/Sour", VitaminsAmount = 17
            };
            Orange orange2 = new Orange {
                Taste = "Sweet/Sour", VitaminsAmount = 19
            };
            Steak steakSoDiploma = new Steak {
                Taste = "Salty", ProteinsAmount = 40
            };
            Egg egg1 = new Egg {
                Taste = "Salty", ProteinsAmount = 30
            };

            //List<Apple> apples = new List<Apple> { apple1, apple2, apple3, new JapanApple { JapanProperty = 2 } };
            //List<Orange> oranges = new List<Orange> { orange1, orange2 };
            //List<Egg> eggs = new List<Egg> { egg1 };
            //List<Steak> steaks = new List<Steak> { steakSoDiploma };

            List <IJucable> jucables = new List <IJucable> {
                apple1, apple2, apple3, orange1, orange2
            };
            List <IProtein> proteins = new List <IProtein> {
                steakSoDiploma, egg1
            };

            List <IFood> foods = new List <IFood> {
                apple1, apple2, apple3, orange1, orange2, steakSoDiploma, egg1
            };

            foods.Select(x => x.Taste);

            GenericDb <Apple>  appleDb  = new GenericDb <Apple>();
            GenericDb <Orange> orangeDb = new GenericDb <Orange>();
            GenericDb <Steak>  steakDb  = new GenericDb <Steak>();
            GenericDb <Egg>    eggDb    = new GenericDb <Egg>();

            //GenericDb<string> stringDb = new GenericDb<string>();

            //appleDb appleDb1 = new appleDb()

            appleDb.AddItem(apple1);
            appleDb.AddItem(apple2);
            appleDb.AddItem(apple3);
            orangeDb.AddItem(orange1);
            orangeDb.AddItem(orange2);
            steakDb.AddItem(steakSoDiploma);
            eggDb.AddItem(egg1);


            List <Apple>  apples  = appleDb.GetItems();
            List <Orange> oranges = orangeDb.GetItems();
            List <Egg>    eggs    = eggDb.GetItems();
            List <Steak>  steaks  = steakDb.GetItems();



            Console.WriteLine("Choose 1. Juces 2. Proteins 3. All Food");
            string answer = Console.ReadLine();

            if (int.Parse(answer) == 1)
            {
                //foreach (var apple in apples)
                //{
                //    Console.WriteLine();
                //}

                //foreach (var orange in oranges)
                //{
                //    Console.WriteLine();
                //}

                foreach (var juicable in jucables)
                {
                    Console.WriteLine();
                }
            }
            else if (StrToInt(answer) == 2)
            {
                //foreach (var steak in steaks)
                //{
                //    Console.WriteLine();
                //}

                //foreach (var egg in eggs)
                //{
                //    Console.WriteLine();
                //}

                foreach (var protein in proteins)
                {
                    Console.WriteLine();
                }
            }
            else if (answer.ToInt() == 3)
            {
                //foreach (var jucable in jucables)
                //{
                //    Console.WriteLine();
                //}

                //foreach (var protein in proteins)
                //{
                //    Console.WriteLine();
                //}

                foreach (var food in foods)
                {
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Wrong input");
            }

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            GenericDb <Product> products = new GenericDb <Product>();
            GenericDb <Order>   orders   = new GenericDb <Order>();
            GenericDb <User>    users    = new GenericDb <User>();

            Product p1 = new Product
            {
                Id          = 1,
                Title       = "Coca Cola",
                Description = "Drink"
            };

            Product p2 = new Product
            {
                Id          = 2,
                Title       = "Chips",
                Description = "Nice Chips"
            };

            products.Add(p1);
            products.Add(p2);
            //Storage.AddProduct(p1);
            //Storage.AddProduct(p2);

            Order o1 = new Order
            {
                Id       = 1,
                Address  = "Skopje",
                Receiver = "Risto"
            };

            Order o2 = new Order
            {
                Id       = 2,
                Address  = "Krusevo",
                Receiver = "Radmila"
            };

            //Storage.AddOrder(o1);
            //Storage.AddOrder(o2);
            orders.Add(o1);
            orders.Add(o2);

            User u1 = new User
            {
                Id   = 1,
                Name = "Risto"
            };

            User u2 = new User
            {
                Id   = 2,
                Name = "Radmila"
            };

            users.Add(u1);
            users.Add(u2);

            users.PrintAll();
            products.PrintAll();
            orders.PrintAll();

            users.RemoveById(1);
            users.PrintAll();

            Console.WriteLine(orders.GetById(2)?.GetInfo());
            Console.WriteLine(products.GetByIndex(0).GetInfo());
        }