示例#1
0
        public void PlaceOrder(Customer customer,
                               Order order, Payment payment,
                               bool allowSplitOrders, bool emailReceipt)
        {
            customerRepository = new CustomerRepository();
            customerRepository.Add(customer);

            orderRepository = new OrderRepository();
            orderRepository.Add(order);

            inventoryRepository = new InventoryRepository();
            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment();

            if (emailReceipt)
            {
                customer.ValidateEmail();
                customerRepository.Update();

                emailLibrary = new EmailLibrary();
                emailLibrary.SendEmail(customer.EmailAddress,
                                       "Here is your receipt");
            }
        }
示例#2
0
        // flags usually go at the end
        public void PlaceOrder(Customer customer,
                               Order order,
                               Payment payment,
                               bool allowSplitOrders,
                               bool emailReceipt)
        {
            CustomerRepository.Add(customer);

            OrderRepository.Add(order);

            InventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment();

            if (emailReceipt)
            {
                // returnin an object makes the code more readable
                var result = customer.ValidateEmail();

                if (result.Success)
                {
                    CustomerRepository.Update();

                    EmailLibrary.SendEmail(customer.EmailAddress, "Here is your receipt");
                }
            }
        }
示例#3
0
        public void PlaceOrder(Customer customer, Order order, Payment payment, bool emailReceipt)
        {
            //1. Add New Customer
            customerRepository.Add(customer);

            //2. Add Order
            orderRepository.Add(order);

            //3. Substract from Inventory
            inventoryRepository.OrderItems(order);

            //4. Process Payment
            payment.ProcessPayment(payment);

            //5. Email Notifications
            if (emailReceipt)
            {
                var isValidEmail = customer.ValidateEmail();

                if (isValidEmail)
                {
                    customerRepository.Update();

                    Email.Send(customer.EmailAddress, "Order Sent");
                }
            }
        }