public void AddProductToOrder()
        {
            // add customer to DB and get id
            int CustomerId = _customerManager.AddCustomer(_customer);

            // add the customerId to _testOrder
            _testOrder.CustomerId = CustomerId;
            // add the customerId to _testProduct
            _testProduct.CustomerId = CustomerId;

            // add a test order
            int orderId = _orderManager.AddOrder(_testOrder);
            // add a test product
            int productId = _productManager.AddProduct(_testProduct);

            // add product to order by creating a record in the OrderProduct join table
            _orderManager.AddProductToOrder(orderId, productId);

            // Retrieve the order that was just added to db
            Product returnedProduct = _orderManager.GetSingleProductFromOrder(orderId, productId);

            // assert that the product stored on the order is the same product that we sent in.
            Assert.Equal(returnedProduct.Id, productId);
            Assert.Equal(55.25, returnedProduct.Price);
            Assert.Equal(returnedProduct.Quantity, 1);
            Assert.Equal(returnedProduct.Name, "Bicycle");
            Assert.Equal(returnedProduct.Description, "Awesome bike");
        }
        public void CheckIfProductIsOnOrder()
        {
            Customer c = new Customer();

            c.Name          = "DELETE TEST";
            c.StreetAddress = "DELETE ST.";
            c.City          = "Detroit";
            c.State         = "DLState";
            c.PostalCode    = "123456";
            c.PhoneNumber   = "615-555-5555";

            int cId = _customerManager.AddCustomer(c);

            // add new product with product name
            _product             = new Models.Product();
            _product.Name        = "Kite";
            _product.CustomerId  = cId;
            _product.Price       = 45.00;
            _product.Description = "UNPAID TEST";
            _product.Quantity    = 3;

            ProductManager productManager = new ProductManager(_db);
            int            prodId         = productManager.AddProduct(_product);
            OrderManager   orderManager   = new OrderManager(_db);

            Order order = new Order(cId);
            int   ordId = orderManager.AddOrder(order);

            orderManager.AddProductToOrder(ordId, prodId);

            // should be an unpaid order
            bool isOnOrder = productManager.IsProductOnOrder(prodId);

            Assert.True(isOnOrder);
        }
        //private ProductManager _pm;

        // add product to customer's cart
        public void AddOrderStringBuilder(ProductManager _pm)
        {
            Console.Clear();
            int X;
            //Order order = new Order();
            //Placeholder for product Id
            var counter = 1;

            Console.Clear();
            Console.WriteLine("Choose Product:");
            List <Product> products = null;

            // function to pull list of products to loop through
            products = _pm.GetAvailable();
            foreach (var product in products)
            {
                Console.WriteLine($"{product.id}. {product.Name}");
                counter++;
            }
            Console.WriteLine($"Press {counter} to quit");
            Console.Write("> ");
            X = Int32.Parse(Console.ReadLine());
            if (X == counter)
            {
                Menus.MainMenu();
            }
            else
            {
                OrderManager.AddProductToOrder(X, ChooseActiveCustomerManager.activeCustomer);
                AddOrderStringBuilder(_pm);
            }
        }
Example #4
0
        public void CanAddOrderToFile()
        {
            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            OrderManager manager  = OrderManagerFactory.Create();
            Order        newOrder = new Order();

            DateTime date = new DateTime(2018, 01, 01);

            newOrder.OrderDate    = date;
            newOrder.CustomerName = "Bill Johnson";
            newOrder.State        = "PA";
            newOrder.ProductType  = "Wood";
            newOrder.Area         = 300;

            manager.AddProductToOrder(newOrder);
            manager.AddStateToOrder(newOrder);

            manager.SaveOrder(newOrder);

            OrderLookupResponse response = manager.LookupOrders(newOrder.OrderDate);

            Assert.AreEqual(2, response.ListOfOrders.Count);
        }
Example #5
0
        public void AddProductToOrderShould()
        {
            CustomerManager    _customerManager    = new CustomerManager(_db);
            ActiveCustomer     _activeManager      = new ActiveCustomer();
            ProductManager     _productManager     = new ProductManager(_db);
            ProductTypeManager _productTypeManager = new ProductTypeManager(_db);
            var newCustomerId = _customerManager.AddCustomer(new Customer("Bob", "Some Street", "City", "TN", 12345, "5555555555"));

            _activeManager.setActiveCustomerId(newCustomerId);
            var newProductTypeId = _productTypeManager.AddProductType(new ProductType("taco"));
            var newProductId     = _productManager.CreateProduct(new Product(newProductTypeId, "taco", 25, "string description", 25, newCustomerId));
            var orderId          = _orderManager.CreateOrder();
            var orderProductId   = _orderManager.AddProductToOrder(newProductId, orderId);

            Assert.IsType <int>(orderProductId);
        }
        public void UserShouldBeAbleToAddAProductToCustomerOrder()
        {
            Product coolProduct = new Product();

            bool productAddedToOrder = _orderManager.AddProductToOrder(coolProduct);

            Assert.Equal(productAddedToOrder, true);
        }
Example #7
0
        public void CanEditOrderFromFile()
        {
            OrderManager manager     = OrderManagerFactory.Create();
            DateTime     date        = new DateTime(2018, 01, 01);
            Order        editedOrder = manager.GetSpecificOrder(date, 1);

            OrderLookupResponse response = manager.LookupOrders(date);

            Order check = response.ListOfOrders[1];

            Assert.AreEqual(1, check.OrderNumber);
            Assert.AreEqual("Bill Johnson", check.CustomerName);
            Assert.AreEqual("PA", check.State);
            Assert.AreEqual(6.75M, check.TaxRate);
            Assert.AreEqual("Wood", check.ProductType);
            Assert.AreEqual(300, check.Area);
            Assert.AreEqual(5.15M, check.CostPerSquareFoot);
            Assert.AreEqual(4.75M, check.LaborCostPerSquareFoot);
            Assert.AreEqual(1545, check.MaterialCost);
            Assert.AreEqual(1425, check.LaborCost);
            Assert.AreEqual(200.475m, check.Tax);
            Assert.AreEqual(3170.475m, check.Total);

            editedOrder.OrderDate    = date;
            editedOrder.CustomerName = "Jake";
            editedOrder.State        = "PA";
            editedOrder.Area         = 350;

            manager.AddProductToOrder(editedOrder);
            manager.AddStateToOrder(editedOrder);

            manager.SaveEditedOrder(editedOrder);
            response = manager.LookupOrders(editedOrder.OrderDate);

            Order check2 = response.ListOfOrders[1];

            Assert.AreEqual(1, check2.OrderNumber);
            Assert.AreEqual("Jake", check2.CustomerName);
            Assert.AreEqual("PA", check2.State);
            Assert.AreEqual(6.75M, check2.TaxRate);
            Assert.AreEqual("Wood", check2.ProductType);
            Assert.AreEqual(350, check2.Area);
            Assert.AreEqual(5.15M, check2.CostPerSquareFoot);
            Assert.AreEqual(4.75M, check2.LaborCostPerSquareFoot);
            Assert.AreEqual(1802.5, check2.MaterialCost);
            Assert.AreEqual(1662.5, check2.LaborCost);
            Assert.AreEqual(233.8875, check2.Tax);
            Assert.AreEqual(3698.8875, check2.Total);
        }
        /*
         * Class:   AddProductCart
         * Purpose: method that is called from Program.cs switch case: 5
         *       accepts 3 arguments
         *       first argument is an Instance of the Class ProductManager
         *       second argument is an Instance of the Class OrderManager
         *       third is the CustomerId that was selected and stored from switch case: 2
         *       Assigns the product to the productOrder table
         * Author:  Dilshod
         */
        public static void DoAction(OrderManager om, ProductManager pm, CustomerManager cm)
        {
            // Get list of Products
            var products = pm.GetProductList();
            int counter;
            int chooseProduct;

            // Checks if there's an active customer. If not, kicks them to the main menu
            if (CustomerManager.activeCustomer == 0)
            {
                Console.Clear();
                Console.WriteLine("* Please choose an active customer before continuing *");
                Console.WriteLine("* Press 'ENTER' to return to the main menu *");
                Console.ReadLine();
            }
            else
            {
                int orderId;

                int activeOrder = om.CheckActiveOrder();
                if (activeOrder != 0)
                {
                    orderId = activeOrder;
                }
                else
                {
                    orderId = om.CreateOrder(CustomerManager.activeCustomer);
                }

                do
                {
                    Console.Clear();
                    counter = 1;
                    Console.WriteLine("Choose a product to add to your cart");
                    foreach (var product in products)
                    {
                        Console.WriteLine($"{counter++}. {product.Name}");
                    }
                    Console.WriteLine($"Press {counter} to quit");
                    Console.Write("> ");
                    chooseProduct = int.Parse(Console.ReadLine());
                    if (chooseProduct < counter)
                    {
                        om.AddProductToOrder(chooseProduct, orderId);
                    }
                }while (chooseProduct < counter);
            }
        }
        public static void DoAction(OrderManager orderManager)
        {
            Console.Clear();
            Console.WriteLine("What do you want to buy?!");

            List <Product> products = orderManager.GetAllProducts();

            foreach (Product product in products)
            {
                Console.WriteLine($"{product.Id}. {product.Name} - ${product.Price}.00");
            }

            Console.Write("> ");
            int productToBuy = int.Parse(Console.ReadLine());

            orderManager.AddProductToOrder(productToBuy);
        }
Example #10
0
        public void AddProductToOrder()
        {
            Customer _currentCustomer = new Customer();

            _currentCustomer.customerID     = 1;
            _currentCustomer.firstName      = "Brain";
            _currentCustomer.lastName       = "Pinky";
            _currentCustomer.streetAddress  = "114 Street Place";
            _currentCustomer.state          = "Tennesseetopia";
            _currentCustomer.postalCode     = 55555;
            _currentCustomer.phoneNumber    = "555-123-4567";
            CustomerManager.currentCustomer = _currentCustomer;

            int ProductID = 1;

            _om.CreateNewOrder(ProductID);
            var result = _om.AddProductToOrder(ProductID);

            Assert.IsType <int>(result);
        }
Example #11
0
        public void Execute()
        {
            OrderManager manager  = OrderManagerFactory.Create();
            Order        newOrder = new Order();
            DateTime     date;
            bool         isValid = false;

            Console.Clear();
            Console.WriteLine("Add an order");
            Console.WriteLine("*********************************");

            while (!isValid)
            {
                Console.Clear();
                Console.Write("Enter the date (mm/dd/yyyy) that you would like to create the order for: ");
                //confirm date is valid and in the future.
                if (DateTime.TryParse(Console.ReadLine(), out date))
                {
                    isValid = true;
                }
                else
                {
                    isValid = false;
                }

                if (date > DateTime.Now)
                {
                    isValid            = true;
                    newOrder.OrderDate = date;
                }
                else
                {
                    Console.WriteLine("Error: Must be a valid future date\nPress any key to re enter date");
                    Console.ReadKey();
                    isValid = false;
                }
            }
            isValid = false;


            while (!isValid)
            {
                Console.Clear();
                Console.Write("Please enter the customer name: ");
                //confirm name is not blank
                newOrder.CustomerName = Console.ReadLine().Replace(",", "^");
                if (string.IsNullOrWhiteSpace(newOrder.CustomerName))
                {
                    Console.WriteLine("Error: Name entered is not valid.\nPress any key to re enter name");
                    Console.ReadKey();
                    isValid = false;
                }
                else
                {
                    isValid = true;
                }
            }
            isValid = false;

            while (!isValid)
            {
                Console.Clear();
                ConsoleIO.DisplayStateDetails(manager.ListStates());
                Console.WriteLine("From the list above, please enter the state the customer is located in: ");
                //confirm state exists within repo
                newOrder.State = Console.ReadLine();
                manager.AddStateToOrder(newOrder);
                if (manager.ListStates().Any(o => o.StateAbbreviation == newOrder.State || o.StateName == newOrder.State))
                {
                    isValid = true;
                }
                else
                {
                    Console.WriteLine("Error: State entered is not a valid state.\nPress any key to re enter state");
                    Console.ReadKey();
                    isValid = false;
                }
            }
            isValid = false;

            while (!isValid)
            {
                Console.Clear();
                ConsoleIO.DisplayProductDetails(manager.ListProducts());
                Console.WriteLine("From the list above, please enter the name of the product type you would like: ");
                //confirm product exists within repo
                newOrder.ProductType = Console.ReadLine();
                manager.AddProductToOrder(newOrder);
                if (manager.ListProducts().Any(p => p.ProductType == newOrder.ProductType))
                {
                    isValid = true;
                }
                else
                {
                    Console.WriteLine("Error: Product type entered is not valid.\nPress any key to re enter product type");
                    Console.ReadKey();
                    isValid = false;
                }
            }
            isValid = false;

            while (!isValid)
            {
                Console.Clear();
                Console.Write("please enter the area of your project space in sq feet (must be at least 100 sq. ft.): ");
                int input = 0;
                //confirm area is at least 100 sq ft
                int.TryParse(Console.ReadLine(), out input);
                newOrder.Area = input;
                if (newOrder.Area >= 100)
                {
                    isValid = true;
                }
                else
                {
                    Console.WriteLine("Error: Area entered is not valid.\nPress any key to re enter area");
                    Console.ReadKey();
                    isValid = false;
                }
            }
            isValid = false;

            while (!isValid)
            {
                ConsoleIO.DisplaySpecificOrder(newOrder);
                Console.WriteLine("Would you like to place this order? (Y/N)");
                string answer = Console.ReadLine().ToString();

                switch (answer.ToLower())
                {
                case "y":
                    manager.SaveOrder(newOrder);
                    isValid = true;
                    break;

                case "yes":
                    manager.SaveOrder(newOrder);
                    isValid = true;
                    break;

                case "n":
                    isValid = true;
                    break;

                case "no":
                    isValid = true;
                    break;

                default:
                    isValid = false;
                    break;
                }
            }
        }
Example #12
0
        public void Execute()
        {
            OrderManager manager     = OrderManagerFactory.Create();
            DateTime     orderDate   = new DateTime();
            Order        orderToEdit = new Order();
            int          orderNumber = 0;
            bool         isValid     = false;

            Console.Clear();
            Console.WriteLine("Edit an order");
            Console.WriteLine("*********************************");

            while (!isValid)
            {
                Console.Clear();
                Console.Write("Enter the date (mm/dd/yyyy) of the order to be edited: ");
                //confirm valid date
                if (DateTime.TryParse(Console.ReadLine(), out orderDate))
                {
                    isValid = true;
                }
                else
                {
                    Console.WriteLine("Error: Invalid date entered\nPress any key to re enter date");
                    Console.ReadKey();
                    isValid = false;
                }
            }
            isValid = false;

            Console.Write("Enter the order number of the order to be edited: ");
            int.TryParse(Console.ReadLine(), out orderNumber);

            orderToEdit = manager.GetSpecificOrder(orderDate, orderNumber);

            Console.Write($"Enter customer name (currently: {orderToEdit.CustomerName.Replace("^",",")}): ");
            string name = Console.ReadLine();

            if (!(string.IsNullOrWhiteSpace(name)))
            {
                orderToEdit.CustomerName = name;
            }

            while (!isValid)
            {
                List <Tax> stateList = manager.ListStates();
                ConsoleIO.DisplayStateDetails(stateList);
                Console.Write($"Enter the customer state (currently: {orderToEdit.State}):  ");
                string state = Console.ReadLine();
                if (!(string.IsNullOrWhiteSpace(state)))
                {
                    orderToEdit.State = state;
                    manager.AddStateToOrder(orderToEdit);
                    if (manager.ListStates().Any(o => o.StateAbbreviation == orderToEdit.State || o.StateName == orderToEdit.State))
                    {
                        isValid = true;
                    }
                    else
                    {
                        Console.WriteLine("Error: State entered is not a valid state.\nPress any key to re enter state");
                        Console.ReadKey();
                        isValid = false;
                    }
                }
                else
                {
                    isValid = true;
                }
            }
            isValid = false;

            while (!isValid)
            {
                List <Product> prodList = manager.ListProducts();
                ConsoleIO.DisplayProductDetails(prodList);
                Console.Write($"Enter the product type (currently: {orderToEdit.ProductType}):  ");
                string productType = Console.ReadLine();
                if (!(string.IsNullOrWhiteSpace(productType)))
                {
                    orderToEdit.ProductType = productType;
                    manager.AddProductToOrder(orderToEdit);
                    if (manager.ListProducts().Any(p => p.ProductType == orderToEdit.ProductType))
                    {
                        isValid = true;
                    }
                    else
                    {
                        Console.WriteLine("Error: Product type entered is not valid.\nPress any key to re enter product type");
                        Console.ReadKey();
                        isValid = false;
                    }
                }
                else
                {
                    isValid = true;
                }
            }
            isValid = false;

            while (!isValid)
            {
                Console.Write($"Enter the area (currently: {orderToEdit.Area}):  ");
                int area = 0;
                int.TryParse(Console.ReadLine(), out area);
                if (area != 0)
                {
                    orderToEdit.Area = area;
                    if (orderToEdit.Area >= 100)
                    {
                        isValid = true;
                    }
                    else
                    {
                        Console.WriteLine("Error: Area entered is not valid.\nPress any key to re enter area");
                        Console.ReadKey();
                        isValid = false;
                    }
                }
                else
                {
                    isValid = true;
                }
            }
            isValid = false;

            while (!isValid)
            {
                ConsoleIO.DisplaySpecificOrder(orderToEdit);
                Console.WriteLine("Would you like to save this order? Y/N");
                string answer = Console.ReadLine().ToString();

                switch (answer.ToLower())
                {
                case "y":
                    manager.SaveEditedOrder(orderToEdit);
                    isValid = true;
                    break;

                case "yes":
                    manager.SaveEditedOrder(orderToEdit);
                    isValid = true;
                    break;

                case "n":
                    isValid = true;
                    break;

                case "no":
                    isValid = true;
                    break;

                default:
                    isValid = false;
                    break;
                }
            }
        }
        public static void AddProductToOrder(CustomerManager cm, ProductManager pm, OrderManager om)
        {
            Console.Clear();
            int            custID   = CustomerManager.currentCustomer.customerID;
            List <Product> products = pm.GetProductsNotSoldByCustomer(custID);

            //int[] is an array of integers
            int[] choice = DisplayProductList(products);
            do
            {
                int   index       = choice[0] - 1;
                Order ActiveOrder = om.GetActiveCustomerOrder(custID);
                //if there is NOT an active customer, run this
                if (ActiveOrder.orderID == 0)
                {
                    //if user choice is less than product count, create a new order
                    if (choice[0] < products.Count)
                    {
                        om.CreateNewOrder(products[index].productID);
                        //if user choice does not equal the exit number, run this menu again
                    }
                    else if (choice[0] != choice[1])
                    {
                        Console.Clear();
                        Console.WriteLine("That is not a valid option for a product, press enter to continue!");
                        Console.ReadLine();
                        AddProductOrder.AddProductToOrder(cm, pm, om);
                        // if the user choice equals the exit number, exit the menu
                    }
                    else if (choice[0] == choice[1])
                    {
                        break;
                    }
                    //decrement product quantity by one
                    string updateString = $"UPDATE product SET quantity = {products[index].quantity - 1} WHERE productID = {products[index].productID} and quantity > 0";
                    pm.UpdateProduct(updateString);
                    Console.WriteLine($"{products[index].name} successfully added to your order");
                    products = pm.GetProductsNotSoldByCustomer(custID);
                    choice   = DisplayProductList(products);
                }
                //if there IS an active customer, run this
                if (ActiveOrder.orderID != 0)
                {
                    if (choice[0] < products.Count)
                    {
                        om.AddProductToOrder(products[index].productID);
                    }
                    else if (choice[0] != choice[1])
                    {
                        Console.Clear();
                        Console.WriteLine("That is not a valid option for a product, press enter to continue!");
                        Console.ReadLine();
                        AddProductOrder.AddProductToOrder(cm, pm, om);
                    }
                    else if (choice[0] == choice[1])
                    {
                        break;
                    }
                    //decrement product quantity by one
                    string updateString = $"UPDATE product SET quantity = {products[index].quantity - 1} WHERE productID = {products[index].productID} and quantity > 0";
                    pm.UpdateProduct(updateString);
                    Console.WriteLine($"{products[index].name} successfully added to your order");
                    products = pm.GetProductsNotSoldByCustomer(custID);
                    choice   = DisplayProductList(products);
                }
            } while(choice[0] != choice[1]);
            return;
        }
Example #14
0
        public void AddProductToOrderShould()
        {
            var result = OrderManager.AddProductToOrder(1, 1);

            Assert.IsType <int>(result);
        }
        public void AddProductToOrder()
        {
            var id = _manager.AddProductToOrder(1, 2); // pass product id and order id to the manager

            Assert.IsType <int>(id);
        }
        /*
         *  Summary: Displays the add customer menu to the user
         */
        public void Show()
        {
            // get a list of all products in the database
            List <Product> AllProducts = _productManager.GetProducts();

            // create variable to hold the user choice
            int output = 0;

            // create a variable to hold a number to use as the menu number.
            int menuNum = 1;

            // create a list of products to hold all the available products with quantities greated than 0
            List <Product> AllAvailableProducts = new List <Product>();

            do
            {
                // start the menuNum at 1 for each loop
                menuNum = 1;

                // Clear the console
                Console.Clear();

                // check if there are products in the database
                if (AllProducts.Count > 0)
                {
                    Console.WriteLine("Choose a Product to add to the order:");
                    Console.WriteLine();

                    // Loop through list of products and only print available products to the console, which are products with a quantity greater than 0.
                    foreach (Product product in AllProducts)
                    {
                        if (_orderManager.hasAvailableQuantity(product))
                        {
                            // add product to list of available products
                            AllAvailableProducts.Add(product);
                            Console.WriteLine($"{menuNum}. {product.Name}");
                            menuNum++;
                        }
                    }
                    // show alert to user if there are no available products
                    if (AllAvailableProducts.Count() < 1)
                    {
                        Console.WriteLine("*** NO PRODUCTS CURRENTLY AVAILABLE TO PURCHASE. ***");
                    }
                }
                else
                {
                    // if there are no products, alert the user
                    Console.WriteLine("*** NO PRODUCTS CURRENTLY IN SYSTEM ***");
                    Console.WriteLine("*** PRESS ENTER TO CONTINUE.        ***");
                }

                // menu option to exit back to main menu. This will always be the last number, no matter how many products are in the system.
                Console.WriteLine($"{menuNum + 1}. Exit back to Main Menu. ");

                Console.Write("> ");
                String enteredKey = Console.ReadLine();
                Console.WriteLine("");
                int.TryParse(enteredKey, out output);

                if (output != menuNum + 1)
                {
                    // find the selected product from the list
                    Product selectedProduct = AllAvailableProducts.ElementAt(output - 1);

                    // retrieve customer's Unpaid order
                    Order customerOrder = _orderManager.GetUnpaidOrder(_customer.Id);

                    // check if the customer does not have a current order started. If they do not, add an order and retrieve it to get the OrderId.
                    if (customerOrder.Id < 1)
                    {
                        Order newOrder = new Order(_customer.Id);
                        customerOrder.Id = _orderManager.AddOrder(newOrder);
                    }

                    // create a record in the OrderProduct table for the relationship of the selected product and the customer's orderId
                    _orderManager.AddProductToOrder(customerOrder.Id, selectedProduct.Id);

                    // Alert the user press enter to continue adding products or to select the option to got back to main menu
                    Console.WriteLine("*** Press ENTER to continue to add products                   ***");
                    Console.WriteLine($"*** Or Choose {menuNum + 1} and press enter to exit back to main menu. ***");
                    int.TryParse(Console.ReadLine(), out output);
                }
            } while (output != menuNum + 1);
        }
        public void AddProductToOrderShould()
        {
            int prodOrdId = _om.AddProductToOrder(12, 32); // First argument is Product Id, second argument is Order Id

            Assert.IsType <int>(prodOrdId);
        }