Esempio n. 1
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");
                }
            }
        }
Esempio n. 2
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");
            }
        }
Esempio n. 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");
                }
            }
        }
Esempio n. 4
0
        public OperationResult PlaceOrder(Customer customer,
                                          Order order,
                                          Payment payment,
                                          bool allowSplitOrders, bool emailReceipt)
        {
            if (customer == null)
            {
                throw new ArgumentException("Customer instance is null");
            }
            if (order == null)
            {
                throw new ArgumentException("Order instance is null");
            }
            if (payment == null)
            {
                throw new ArgumentException("Payment instance is null");
            }
            var op = new OperationResult();

            customerRepository.Add(customer);

            OrderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment(payment);

            if (emailReceipt)
            {
                string message = string.Empty;
                var    result  = customer.ValidateEmail();
                if (result.Success)
                {
                    customerRepository.Update();

                    emailLibrary.SendEmail(customer.Email, "Here is your receipt");
                }
                else
                {
                    //log message
                    if (result.MessageList.Any())
                    {
                        op.AddMessage(result.MessageList[0]);
                    }
                }
            }
            return(op);
        }