Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Purchased a physical product");
            Product physicalProduct = new PhysicalProduct();

            Console.WriteLine(physicalProduct.DoPayment());
            physicalProduct.setDifferentPaymentMethod(new CommissionPayment());
            Console.WriteLine(physicalProduct.DoPayment() + "\n");

            Console.WriteLine("Purchased a book");
            Product bookProduct = new BookProduct();

            Console.WriteLine(bookProduct.DoPayment());
            bookProduct.setDifferentPaymentMethod(new CommissionPayment());
            Console.WriteLine(bookProduct.DoPayment() + "\n");

            Console.WriteLine("Purchased a new membership");
            Product membership = new Membership("new");

            Console.WriteLine(membership.DoPayment() + "\n");


            Console.WriteLine("Upgraded a membership");
            Product membershipUpgrade = new Membership("upgrade");

            Console.WriteLine(membershipUpgrade.DoPayment() + "\n");

            Console.WriteLine("Purchased a Video");
            Product video = new LearningToSki();

            Console.WriteLine(video.DoPayment() + "\n");
        }
Ejemplo n.º 2
0
        //create order class and seed it hardcoded
        //payment is done
        //order line item--product name
        //order entity is main entity. it contains products
        //attribute
        //not able to add new product
        //need to pass actual params
        //Order contatins product
        //Order processing class--ProcessORder()
        //Rules are applied to product --correct
        //Inputs to my function--required in future
        //Pass product time being as input
        //Product depends on payment--payement depends on product--cyclic dependency
        static void Main(string[] args)
        {
            OrderProcessor       order;
            List <IPurchaseRule> payments = new List <IPurchaseRule>();

            Console.WriteLine("Select Product you want to purchase:\n");
            Console.WriteLine("1. Physical Product");
            Console.WriteLine("2. Book");
            Console.WriteLine("3. Membership");
            Console.WriteLine("4. Video");

            int productNumber = int.Parse(Console.ReadLine());

            if (productNumber == 1)
            {
                Console.WriteLine("Purchased a physical product");
                Product physicalProduct = new PhysicalProduct();
                payments.Add(new PackingSlipRule());
                payments.Add(new CommissionPaymentRule());
                order = new OrderProcessor(payments);
                order.ProcessOrder(physicalProduct);

                //Console.WriteLine(physicalProduct.ProcessOrder()); //dopayment to process order.  if order is a seperate class. Should we have order processor class. have processorder method
                //  physicalProduct.setDifferentPaymentMethod(new CommissionPaymentRule());
                //Console.WriteLine(physicalProduct.ProcessOrder() + "\n");
            }
            else if (productNumber == 2)
            {
                Console.WriteLine("Purchased a book");
                Product bookProduct = new BookProduct();
                payments.Add(new DuplicatePackingSlipRule());
                payments.Add(new CommissionPaymentRule());
                order = new OrderProcessor(payments);
                order.ProcessOrder(bookProduct);
                //Console.WriteLine(bookProduct.ProcessOrder());
                ////  bookProduct.setDifferentPaymentMethod(new CommissionPaymentRule());
                //Console.WriteLine(bookProduct.ProcessOrder() + "\n");
            }
            else if (productNumber == 3)
            {
                Console.WriteLine("Press 1 if you want to activate.\n Press 2 if you want to upgrade");
                int selection = int.Parse(Console.ReadLine());
                if (selection == 1)
                {
                    Console.WriteLine("Purchased a new membership");
                    Product membership = new Membership("new");
                    payments.Add(new ActivateMembershipRule());
                    order = new OrderProcessor(payments);
                    order.ProcessOrder(membership);
                    //  Console.WriteLine(membership.ProcessOrder() + "\n");
                }
                else if (selection == 2)
                {
                    Console.WriteLine("Purchase made for upgrading a membership");
                    Product membershipUpgrade = new Membership("upgrade");

                    payments.Add(new UpgradeMembershipRule());
                    order = new OrderProcessor(payments);
                    order.ProcessOrder(membershipUpgrade);
                    //Console.WriteLine(membershipUpgrade.ProcessOrder() + "\n");
                }
            }
            else if (productNumber == 4)
            {
                Console.WriteLine("Purchased a Video");
                Product video = new LearningToSki();
                payments.Add(new FreeFirstAidVideoRule());
                order = new OrderProcessor(payments);
                order.ProcessOrder(video);
                //  Console.WriteLine(video.ProcessOrder() + "\n");
            }
        }
        static void Main(string[] args)
        {
            string   optionSelected = "";
            IPayment payment        = null;

            do
            {
                Console.WriteLine("");
                Console.WriteLine("Select your option");
                Console.WriteLine("1:Make payment for a physical product");
                Console.WriteLine("2:Make payment for a book");
                Console.WriteLine("3:Make payment for a new membership");
                Console.WriteLine("4:Make payment for a membership upgrade");
                Console.WriteLine("5:Make payment for a video");
                Console.WriteLine("0:Exit");
                Console.WriteLine("");
                payment        = null;
                optionSelected = Console.ReadLine();

                switch (optionSelected)
                {
                case "0":
                {
                    Console.WriteLine("Exiting...");
                    break;
                }

                case "1":
                {
                    Console.WriteLine("Payment made for a physical product");
                    payment = new PhysicalProduct(new GenerateCommission());
                    break;
                }

                case "2":
                {
                    Console.WriteLine("Payment made for a book");
                    payment = new Book(new GenerateCommission());
                    break;
                }

                case "3":
                {
                    Console.WriteLine("Payment made for a new membership");
                    payment = new Membership(new NewMember());
                    break;
                }

                case "4":
                {
                    Console.WriteLine("Payment made for a membership upgrade");
                    payment = new Membership(new UpgradeMember());
                    break;
                }

                case "5":
                {
                    Console.WriteLine("Payment made for a video");
                    payment = new Video();
                    break;
                }

                default:
                {
                    Console.WriteLine("Invalid option, try again");
                    break;
                }
                }

                if (payment != null)
                {
                    payment.ExecuteBusinessRules();
                }
            } while (optionSelected != "0");
        }