Beispiel #1
0
        public void GetStores()
        {
            try
            {
                foreach (var item in _locationBL.GetLocations())
                {
                    Console.WriteLine(item.ToString());
                }
                Console.WriteLine("Enter a Store Code to Shop:");
                int      storeCode        = int.Parse(Console.ReadLine());
                Location selectedLocation = _locationBL.GetSpecificLocation(storeCode);
                if (selectedLocation == null)
                {
                    Console.WriteLine("Error - store code not valid");
                }
                else
                {
                    Console.WriteLine($"{selectedLocation.LocationName} Inventory:");
                    foreach (var item in _itemBL.GetItemsByLocation(storeCode))
                    {
                        Console.WriteLine(item.Product.ToString());
                        Console.WriteLine(item.ToString());
                    }
                    Order          newOrder     = new Order(); //create new order object
                    bool           shop         = true;
                    List <Product> cartProducts = new List <Product>();
                    List <int>     cartQuantity = new List <int>();
                    double         totalCost    = 0.0;
                    do
                    {
                        //Product selectedProduct = null;
                        Console.WriteLine();
                        Console.WriteLine("Select ProductID to add product to your order");
                        Console.WriteLine("Type \'Cancel\' to cancel order or \'Finish\' to complete your order");
                        Console.WriteLine("Selection:");
                        string option = Console.ReadLine();
                        if (option == "Cancel" || option == "cancel")
                        {
                            shop = false;
                        }
                        else if (option == "Finish" || option == "finish")
                        {
                            //Create Order
                            newOrder.Total    = totalCost;
                            newOrder.Location = selectedLocation;
                            bool findCustomer = false;
                            do
                            {
                                Customer orderCust = FindCustomer();
                                if (orderCust == null)
                                {
                                    Console.WriteLine("No matching customer found, try searching again");
                                }
                                else
                                {
                                    newOrder.Customer = orderCust;
                                    findCustomer      = true;
                                }
                            }while(!findCustomer);
                            _orderBL.AddOrder(newOrder);

                            //Add products to ProductOrder
                            int oID = _orderBL.FindOrder(newOrder.Total).OrderID;
                            for (int i = 0; i < cartProducts.Count; i++)
                            {
                                ProductOrder po = new ProductOrder();
                                po.Order    = _orderBL.FindOrder(oID);
                                po.Product  = cartProducts[i];
                                po.Quantity = cartQuantity[i];
                                _productOrderBL.AddProductOrder(po);
                                Console.WriteLine("Order Summary:");
                                Console.WriteLine("--------------");
                                po.ToString();
                                _productBL.ProductsByOrder(po.Order.OrderID);
                            }
                            Console.WriteLine("Order successfully placed!");
                            Log.Information("Order Created");
                            shop = false;
                        }
                        else if (option != "Cancel" && option != "Finish")
                        {
                            foreach (var item in _productBL.GetProducts())
                            {
                                if (int.Parse(option) == item.ProductID)
                                {
                                    cartProducts.Add(item);
                                    Console.WriteLine("Enter quantity:");
                                    int quantity = int.Parse(Console.ReadLine());
                                    cartQuantity.Add(quantity);
                                    totalCost = (totalCost) + (item.Price * quantity);
                                }
                            }
                        }
                    }while (shop);
                }
            }
            catch
            {
                Console.WriteLine("Something went wrong...canceling order");
            }
        }
Beispiel #2
0
        public void LocationHistory()
        {
            foreach (var item in _locationBL.GetLocations())
            {
                Console.WriteLine(item.ToString());
            }
            Location loc      = null;
            bool     foundLoc = false;
            int      option;

            do
            {
                Console.WriteLine("Enter store code to view inventory history:");
                option = int.Parse(Console.ReadLine());
                loc    = _locationBL.GetSpecificLocation(option);
                if (loc == null)
                {
                    Console.WriteLine("Invalid location id, please search again");
                }
                else
                {
                    foundLoc = true;
                }
            }while(!foundLoc);
            Console.WriteLine("Select order history format:");
            Console.WriteLine("\t[1] - Date(Ascending)\n\t[2] - Date(Descending)\n\t[3] - Total(Highest)\n\t[4] - Total(Lowest)");
            option = int.Parse(Console.ReadLine());
            switch (option)
            {
            case 1:
                foreach (var item in _orderBL.GetLocationOrderASC(loc.LocationID))
                {
                    Console.WriteLine(item.ToString());
                    _productBL.ProductsByOrder(item.OrderID);
                }
                break;

            case 2:
                foreach (var item in _orderBL.GetLocationOrderDESC(loc.LocationID))
                {
                    Console.WriteLine(item.ToString());
                    _productBL.ProductsByOrder(item.OrderID);
                }
                break;

            case 3:
                foreach (var item in _orderBL.GetLocationOrderASCTotal(loc.LocationID))
                {
                    Console.WriteLine(item.ToString());
                    _productBL.ProductsByOrder(item.OrderID);
                }
                break;

            case 4:
                foreach (var item in _orderBL.GetLocationOrderDESCTotal(loc.LocationID))
                {
                    Console.WriteLine(item.ToString());
                    _productBL.ProductsByOrder(item.OrderID);
                }
                break;

            default:
                Console.WriteLine("Incorrect option, please try again");
                break;
            }
        }