Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.Write("Payment Method: ");
            var method = Console.ReadLine();

            Computer computer;

            var order = new Order
            {
                AmountOfCores = 4,
                AmountOfRam = 32,
                CpuFrequency = 3.0m,
                DriveType = "ssd"
            };

            var processingService = new OrderProcessingService();

            if (method.ToLower() == "cash")
            {
                computer = processingService.MakeCashPurchase(order, 1500m);
            }
            else
            {
                computer = processingService.MakeCreditPurchase(order);
            }

            GiveComputerToCustomer(computer);

            Console.Read();
        }
        public Computer Build(Order order, ComputerBuilder builder)
        {
            builder.SetCores(order.AmountOfCores);
            builder.SetCpuFrequency(order.CpuFrequency);
            builder.SetRam(order.AmountOfRam);
            builder.SetDriveType(order.DriveType);

            Console.WriteLine("Built Computer.");

            return builder.GetComputer();
        }
        public Computer MakeCashPurchase(Order order, decimal amount)
        {
            var register = new CashRegisterService();
            register.OpenDrawer();
            var change = register.MakeChange(order.Price, amount);

            var computer = store.Build(order, computerBuilder);

            factory.PlaceOrder(order);

            return computer;
        }
        public Computer MakeCreditPurchase(Order order)
        {
            var credit = new CreditProcessingService();

            if (!credit.HasCreditAvailable(order.Price))
            {
                throw new Exception("Customer does not have avaiable credit.");
            }

            credit.MakePurchase(order.Price);

            var computer = store.Build(order, computerBuilder);

            factory.PlaceOrder(order);

            return computer;
        }
 public void PlaceOrder(Order order)
 {
     Console.WriteLine("Ordered parts for inventory.");
 }