Exemplo n.º 1
0
        public static Customer Load(int customerId, LoadDataFromDBDelegate loadDataDelegate)
        {
            Customer      customer   = new Customer();
            SqlConnection connection = new SqlConnection(ConnectionString);

            connection.Open();

            //Making this part generic means that it is reusable
            //This can be called by a method that wants to create, delete, create, update customers, etc

            loadDataDelegate(connection, customerId, customer);
            connection.Close();

            return(customer);
        }
Exemplo n.º 2
0
        public bool PlaceOrder(Order order, int customerId)
        {
            LoadDataFromDBDelegate delegateInstanceObj = new LoadDataFromDBDelegate(LoadCustomerFromDB);
            Customer customer = CustomerRepository.Load(customerId, delegateInstanceObj);

            if (order.Amount == 0)
            {
                return(false);
            }

            if (customer.Country == "UK")
            {
                order.VAT = 0.2d;
            }
            else
            {
                order.VAT = 0;
            }

            orderRepository.Save(order);

            return(true);
        }