static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var william = new ExpenseHandler(new Employee("Will", 0));
            var mary    = new ExpenseHandler(new Employee("Mary", 1000));
            var victor  = new ExpenseHandler(new Employee("Victor", 5000));

            william.RegisterNext(mary);
            mary.RegisterNext(victor);

            IExpenseReport   report   = new ExpenseReport(1500);
            ApprovalResponse response = william.Approve(report);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            IExpenseHandler rajiv         = new ExpenseHandler(new Employee("Rajiv", Decimal.Zero));
            IExpenseHandler arunChaudhary = new ExpenseHandler(new Employee("Arun", new Decimal(1000)));
            IExpenseHandler sanjeevDhawan = new ExpenseHandler(new Employee("Sanjeev", new Decimal(5000)));
            IExpenseHandler aviragJain    = new ExpenseHandler(new Employee("Avirag", new Decimal(20000)));

            rajiv.Next(arunChaudhary);
            arunChaudhary.Next(sanjeevDhawan);
            sanjeevDhawan.Next(aviragJain);

            Decimal          expenseReportAmount = 5845000;
            ApprovalResponse response            = rajiv.Approve(expenseReportAmount);

            Console.WriteLine("The request was {0}", response);

            Console.Read();
        }
Пример #3
0
        private static void ReportWithCoR()
        {
            // CoR implementation
            Console.WriteLine("Chain of Responsibility");

            var report = new ExpenseReport(2000m);
            var eh1    = new ExpenseHandler(new Employee("Pylyp", 0m));
            var eh2    = new ExpenseHandler(new Employee("Hasham", 100m));
            var eh3    = new ExpenseHandler(new Employee("Annalisa", 1000m));
            var eh4    = new ExpenseHandler(new Employee("Isabel", 10000m));

            eh1.SetNext(eh2);
            eh2.SetNext(eh3);
            eh3.SetNext(eh4);

            var response = eh1.Approve(report);

            Console.WriteLine("Response {0}", response);
        }
Пример #4
0
        static void Main(string[] args)
        {
            ExpenseHandler william = new ExpenseHandler(new Employee("William Worker", Decimal.Zero));
            ExpenseHandler mary    = new ExpenseHandler(new Employee("Mary Manager", new Decimal(1000)));
            ExpenseHandler victor  = new ExpenseHandler(new Employee("Victor Vicepres", new Decimal(5000)));
            ExpenseHandler paula   = new ExpenseHandler(new Employee("Paula President", new Decimal(20000)));

            william.RegisterNext(mary);
            mary.RegisterNext(victor);
            victor.RegisterNext(paula);

            Decimal expenseReportAmount;

            if (ConsoleInput.TryReadDecimal("Expense report amount:", out expenseReportAmount))
            {
                IExpenseReport expense = new ExpenseReport(expenseReportAmount);

                ApprovalResponse response = william.Approve(expense);

                WriteLine($"The request was {response}.");
                ReadLine();
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            ExpenseHandler William = new ExpenseHandler(new Employee("William Worker", Decimal.Zero));
            ExpenseHandler Mary    = new ExpenseHandler(new Employee("Mary Manager", new decimal(1000)));
            ExpenseHandler Victor  = new ExpenseHandler(new Employee("Victor Vicepres", new decimal(5000)));
            ExpenseHandler Paula   = new ExpenseHandler(new Employee("Paula Pres", new decimal(20000)));

            William.RegisterNext(Mary);
            Mary.RegisterNext(Victor);
            Victor.RegisterNext(Paula);

            Decimal expenseReportAmount;

            do
            {
                Console.Write("Expense Report Amout: ");
                Decimal.TryParse(Console.ReadLine(), out expenseReportAmount);
                IExpenseReport   expense  = new ExpenseReport(expenseReportAmount);
                ApprovalResponse response = William.Approve(expense);
                Console.WriteLine($"The request was {response}");

                Console.WriteLine("Again? ");
            } while (Console.ReadLine() != "");
        }