예제 #1
0
        public PaymentOption GetPaymentOptionForCustomer(Customer customer)
        {
            PaymentOption paymentOption = null;

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.Text;
            //Only access the payment option that matches that customer we have passed in (only getting the first payment option)
            cmd.CommandText = string.Format("SELECT IdPaymentOption, Name, AccountNumber FROM PaymentOption " +
                                            "WHERE IdCustomer = '{0}'", customer.IdCustomer);
            cmd.Connection = _sqlConnection;

            try
            {
                _sqlConnection.Open();
                using (SqlDataReader dataReader = cmd.ExecuteReader())
                {
                    if (dataReader.Read())
                    {
                        paymentOption = new PaymentOption();
                        paymentOption.IdPaymentOption = dataReader.GetInt32(0);
                        paymentOption.IdCustomer      = customer.IdCustomer;
                        paymentOption.Name            = dataReader.GetString(1);
                        paymentOption.AccountNumber   = dataReader.GetString(2);
                    }
                }
            }
            finally
            {
                _sqlConnection.Close();
            }

            return(paymentOption);
        }
예제 #2
0
        public void CreatePaymentOption(PaymentOption paymentOption)
        {
            string command = string.Format("INSERT INTO PaymentOption (IdCustomer, Name, AccountNumber)" +
                                           "VALUES ('{0}', '{1}', '{2}')", paymentOption.IdCustomer, paymentOption.Name, paymentOption.AccountNumber);

            UpdateDataBase(command);
        }
        public PaymentOption GetPaymentOptionForCustomer(Customer customer)
        { // Access the payment option WHERE the customerId matches
            PaymentOption paymentOption = null;

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.Text;
            // Only access the payment option that matches with the customer we have passed in
            cmd.CommandText = string.Format("SELECT IdPaymentOption, Name, AccountNumber FROM PaymentOption " +
                                            "WHERE IdCustomer = '{0}'", customer.IdCustomer);
            cmd.Connection = _sqlConnection;

            try
            {
                _sqlConnection.Open();
                using (SqlDataReader dataReader = cmd.ExecuteReader())
                {
                    if (dataReader.Read())
                    { // Creat a payment option object (but it is not adding to a list, so I think it just creates the last instance)
                        paymentOption = new PaymentOption();
                        paymentOption.IdPaymentOption = dataReader.GetInt32(0);
                        paymentOption.IdCustomer      = customer.IdCustomer;
                        paymentOption.Name            = dataReader.GetString(1);
                        paymentOption.AccountNumber   = dataReader.GetString(2);
                    }
                }
            }
            finally
            {
                _sqlConnection.Close();
            }
            return(paymentOption);
        }
        public void CreatePaymentOption(PaymentOption paymentOption)
        { //add the information that ask the customer to our payment option table
            string command = string.Format("INSERT INTO PaymentOption (IdCustomer, Name, AccountNumber) " +
                                           "VALUES ('{0}', '{1}', '{2}')", paymentOption.IdCustomer, paymentOption.Name, paymentOption.AccountNumber);

            UpdateDataBase(command);
        }
예제 #5
0
        public void CreatePaymentOption()
        {
            Console.WriteLine("Which customer would you like to create a payment option for?");
            Customer         customer         = ChooseCustomer();
            CustomerProducts customerProducts = GetCustomerProducts(customer);
            PaymentOption    paymentOption    = new PaymentOption();

            //get the IdCustomer from the Customer table
            paymentOption.IdCustomer = customer.IdCustomer;

            Console.WriteLine("Enter payment type (e.g. AmEx, Visa, Checking");
            paymentOption.Name = Console.ReadLine();

            Console.WriteLine("Enter account/C.C number");
            paymentOption.AccountNumber = Console.ReadLine();

            customerProducts.Payment = paymentOption;

            //call to update database
            _sqlData.CreatePaymentOption(paymentOption);

            Console.Clear();
        }
예제 #6
0
        public void CreatePaymentOption()
        {
            //create payment option object
            Console.WriteLine("Which customer?");
            // Choose the customer to add the payment option on
            Customer customer = ChooseCustomer();
            // Call GetCustomerProducts with the selected customer
            //  CustomerProducts customerProducts = GetCustomerProducts(customer);
            PaymentOption paymentoption = new PaymentOption();

            //get the IdCustomer from the Customer table ADD MORE COMMENTS LINKING Pk and Fk
            paymentoption.IdCustomer = customer.IdCustomer;

            Console.WriteLine("Enter payment type (e.g. AmEx, Visa, Checking)");
            paymentoption.Name = Console.ReadLine();

            Console.WriteLine("Enter account number ");
            paymentoption.AccountNumber = Console.ReadLine();

            //  customerProducts.Payment = paymentoption;

            //call to update the database
            _sqlData.CreatePaymentOption(paymentoption);
        }