Example #1
0
        public OrderManagerShould()
        {
            // Set string variable prodPath to contain the path to the test database
            string prodPath = System.Environment.GetEnvironmentVariable("BANGAZON_TEST_DB");
            // Create connection to test database and capture in DatabaseConnection variable db
            DatabaseConnection db = new DatabaseConnection(prodPath);

            // Set the private DatabaseConnection variable of _db to equal the DatabaseConnection of db
            _db = db;
            // Ensure there is a database with tables at the end of the test database connection
            DatabaseStartup databaseStartup = new DatabaseStartup(_db);

            /*  Set the private OrderManager variable _orderManager to be a new instance of
             *  OrderManager connected to the test database */


            _orderManager = new OrderManager(_db);
            // Create a new Orderz called _orderz for test and set the properties
            _orderz               = new Orderz();
            _orderz.CustomerId    = 1;
            _orderz.PaymentTypeId = 1;
            _orderz.DateCreated   = DateTime.Now;
            // Create a new Orderz for CustomerId 1 with no PaymentTypeId
            _orderz2               = new Orderz();
            _orderz2.CustomerId    = 1;
            _orderz2.PaymentTypeId = null;
            _orderz2.DateCreated   = DateTime.Now;
            // Create a new Orderz for CustomerId 2 with a PaymentTypeId
            _orderz3               = new Orderz();
            _orderz3.CustomerId    = 2;
            _orderz3.PaymentTypeId = 1;
            _orderz3.DateCreated   = DateTime.Now;
        }
        // Author: Leah Duvic and Greg Turner
        // Purpose: Completing customer order by adding the payment type.

        public Orderz CompleteOrderz(int orderId, int paymentTypeId)
        {
            Orderz updatedOrder = new Orderz();

            _db.Insert($"UPDATE Orderz SET PaymentTypeId = {paymentTypeId} WHERE OrderId = {orderId}");
            updatedOrder = GetSingleOrderz(orderId);
            return(updatedOrder);
        }
        /*
         * Author: Greg Turner
         * Purpose: Query the database for the Orderz with the same OrderId as the
         *      one provided.
         */
        public Orderz GetSingleOrderz(int Id)
        {
            Orderz singleOrderz = new Orderz();

            _db.Query($"SELECT * FROM Orderz WHERE Orderz.OrderId = {Id};", (SqliteDataReader reader) => {
                while (reader.Read())
                {
                    singleOrderz.OrderId       = reader.GetInt32(0);
                    singleOrderz.CustomerId    = reader.GetInt32(1);
                    singleOrderz.PaymentTypeId = reader.GetInt32(2);
                    singleOrderz.DateCreated   = reader.GetDateTime(3);
                }
            });
            return(singleOrderz);
        }
        public OrderProductManagerShould()
        {
            // Set string variable prodPath to contain the path to the test database
            string prodPath = System.Environment.GetEnvironmentVariable("BANGAZON_TEST_DB");
            // Create connection to test database and capture in DatabaseConnection variable db
            DatabaseConnection db = new DatabaseConnection(prodPath);

            // Set the private DatabaseConnection variable of _db to equal the DatabaseConnection of db
            _db = db;
            // Ensure there is a database with tables at the end of the test database connection
            DatabaseStartup databaseStartup = new DatabaseStartup(_db);

            /*  Set the private OrderProduct variable _OrderProduct to be a new instance of
             *  OrderProduct connected to the test database */


            _orderProductManager = new OrderProductManager(_db);
            _orderManager        = new OrderManager(_db);
            _productManager      = new ProductManager(_db);

            // Create a new Orderz called _orderz for test and set the properties
            _orderz               = new Orderz();
            _orderz.CustomerId    = 1;
            _orderz.PaymentTypeId = 1;
            _orderz.DateCreated   = DateTime.Now;

            // Create a new Product called _product for test and set the properties
            _product             = new Product();
            _product.ProductType = "transpotation";
            _product.CustomerId  = 1;
            _product.Title       = "Bike";
            _product.Description = "Blue Bike";
            _product.Price       = 2.00;
            _product.Quantity    = 2;
            _product.DateCreated = DateTime.Now;

            _product2             = new Product();
            _product2.ProductType = "transportation";
            _product2.CustomerId  = 1;
            _product2.Title       = "Horse";
            _product2.Description = "Blue Horse";
            _product2.Price       = 3.00;
            _product2.Quantity    = 4;
            _product2.DateCreated = DateTime.Now;
        }
        /*
         * Author: Greg Turner
         * Purpose: Add an Orderz entry into the database Orderz table using the details
         *      in the ticket provided.
         */
        public int AddNewOrderz(Orderz ticket)
        {
            int id = _db.Insert($"insert into Orderz values (null, '{ticket.CustomerId}', '{ticket.PaymentTypeId}', '{ticket.DateCreated}')");

            return(id);
        }