예제 #1
0
        public void AddOrdersShouldAdd(int selectProd, int selectCust, int citySelect, int quant, string dateString)
        {
            //Arrange
            OrderData order = new OrderData();

            //Act
            Action act = () => order.CreateOrderDB(selectProd, selectCust, citySelect, quant, dateString);

            //Assert
            Assert.Throws <FormatException>(act);
        }
예제 #2
0
        public ActionResult CreateOrder(IFormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                int quantity = int.Parse(collection["Quantity"]);
                orderData.CreateOrderDB(product, customer, location, quantity);

                return(RedirectToAction(nameof(ListOrders)));
            }
            catch
            {
                return(View());
            }
        }
예제 #3
0
        static void ManageOrdersMenu()
        {
            Order        order        = new Order();
            OrderData    orderData    = new OrderData();
            ProductData  dataProduct  = new ProductData();
            CustomerData dataCustomer = new CustomerData();

            int menuChoice = 0;

            do
            {
                Console.Clear();
                Console.WriteLine("1. Create an Order");
                Console.WriteLine("2. View All Orders");
                Console.WriteLine("3. Display Order History of a Customer");
                Console.WriteLine("4. Display Order History of a Store Location");
                Console.WriteLine("5+. Go Back");

                Console.WriteLine("\nEnter Your Choice: ");
                menuChoice = Int32.Parse(Console.ReadLine());
                Log.Information("Order Menu Choice {0}", menuChoice);

                switch (menuChoice)
                {
                case 1:

                    int    selectProd = 0, selectCust = 0, citySelect = 0;
                    int    quant      = 0;
                    string dateString = "";

                    bool allowedCity = true, allowedQuant = true, allowedProduct = true, allowedCustomer = true;
                    bool dateFormat = false, caughException = false;

                    List <Product>  tempDisplayProduct = new List <Product>();
                    List <Customer> tempData           = new List <Customer>();

                    #region Serialized Create

                    /*
                     #region Display+Select Product
                     * while (allowedProduct)
                     * {
                     *  Console.Clear();
                     *  bool doneSelection = false;
                     *  int addMore = 1;
                     *
                     *  List<int> selectedProducts = new List<int>();
                     *
                     *  tempDisplayProduct = dataProduct.DisplayProducts(jsonFilePathProducts);
                     *  while (!doneSelection)
                     *  {
                     *      Console.Clear();
                     *      Console.WriteLine("Products");
                     *      if (tempDisplayProduct.Count != 0)
                     *      {
                     *          for (int i = 0; i < tempDisplayProduct.Count; i++)
                     *          {
                     *              Console.WriteLine(" {0}. {1} | ID: {2}", i + 1, tempDisplayProduct[i].ProductName, tempDisplayProduct[i].Id);
                     *          }
                     *      }
                     *      else
                     *      {
                     *          Console.WriteLine("No Data Present");
                     *      }
                     *
                     *      Console.WriteLine("Please Select Product: ");
                     *      selectProd = Int32.Parse(Console.ReadLine());
                     *
                     *
                     *      if (selectProd > dataProduct.ProductCount + 1)
                     *      {
                     *          allowedProduct = true;
                     *          Console.WriteLine("Selected an Invalid Product. Press any key to Try Again.");
                     *          Console.ReadKey();
                     *      }
                     *      else
                     *      {
                     *          allowedProduct = false;
                     *      }
                     *      Console.WriteLine("Would you like to add more Products?");
                     *      Console.WriteLine("1. YES");
                     *      Console.WriteLine("2. NO");
                     *      Console.WriteLine("Please Enter Your Choice: ");
                     *      addMore = Int32.Parse(Console.ReadLine());
                     *
                     *      if (addMore == 1)
                     *      {
                     *          doneSelection = false;
                     *      }
                     *      else if (addMore == 2)
                     *      {
                     *          doneSelection = true;
                     *      }
                     *      else
                     *      {
                     *          doneSelection = true;
                     *          Console.WriteLine("Invalid Choice Entered\nNo more products will be added\nPress any key to continue");
                     *          Console.ReadKey();
                     *      }
                     *  }
                     * }
                     *
                     #endregion
                     *
                     #region Display+Select Customer
                     * while (allowedCustomer)
                     * {
                     *  Console.Clear();
                     *  tempData = dataCustomer.DisplayCustomers(jsonFilePathCustomers);
                     *
                     *  Console.Clear();
                     *  Console.WriteLine("Please Select a Customer");
                     *  if (tempData.Count != 1)
                     *  {
                     *      for (int i = 0; i < tempData.Count; i++)
                     *      {
                     *          Console.WriteLine(" {0}. {1} {2}", i + 1, tempData[i].FirstName, tempData[i].LastName);
                     *      }
                     *  }
                     *  else
                     *  {
                     *      Console.WriteLine("No Data Present");
                     *  }
                     *
                     *  Console.WriteLine("Please Select Customer: ");
                     *  selectCust = Int32.Parse(Console.ReadLine());
                     *
                     *  if (selectCust > dataCustomer.CustomerCount + 1)
                     *  {
                     *      allowedCustomer = true;
                     *      Console.WriteLine("Selected an Invalid Customer. Press any key to Try Again.");
                     *      Console.ReadKey();
                     *  }
                     *  else
                     *  {
                     *      allowedCustomer = false;
                     *  }
                     * }
                     #endregion
                     *
                     #region Display+Select Location
                     * while (allowedCity)
                     * {
                     *  Console.Clear();
                     *  for (int i = 0; i < tempDisplayProduct[selectProd - 1].location.Count; i++)
                     *  {
                     *      Console.WriteLine("{0}. {1} ({2})", i + 1, tempDisplayProduct[selectProd - 1].location[i].City, tempDisplayProduct[selectProd - 1].location[i].Inventory);
                     *  }
                     *
                     *  Console.WriteLine("Select The Location: ");
                     *  citySelect = Int32.Parse(Console.ReadLine());
                     *
                     *  if (citySelect > tempDisplayProduct[selectProd - 1].location.Count + 1)
                     *  {
                     *      allowedCity = true;
                     *      Console.WriteLine("Please Select a Valid City");
                     *  }
                     *  else
                     *  {
                     *      allowedCity = false;
                     *  }
                     * }
                     #endregion
                     *
                     #region  Enter Quantity
                     *
                     * while (allowedQuant)
                     * {
                     *  Console.Clear();
                     *  Console.WriteLine("Enter the Quantity: ");
                     *  quant = Int32.Parse(Console.ReadLine());
                     *
                     *  if (quant > tempDisplayProduct[selectProd - 1].location[citySelect - 1].Inventory)
                     *  {
                     *      Console.WriteLine("Not Enough Copies left in the Inventory");
                     *      Console.WriteLine("Press Any Key To Try Again");
                     *      Console.ReadKey();
                     *      allowedQuant = true;
                     *  }
                     *  else if (quant > 5)
                     *  {
                     *      Console.WriteLine("Enter a Valid Quantity [Order Limit: 5]");
                     *      Console.WriteLine("Press Any Key To Try Again");
                     *      Console.ReadKey();
                     *      allowedQuant = true;
                     *  }
                     *  else
                     *  {
                     *      allowedQuant = false;
                     *  }
                     * }
                     #endregion
                     *
                     #region Enter Date
                     * Console.Clear();
                     * Console.WriteLine("Enter Date and Time for the Order: ");
                     * dateString = Console.ReadLine();
                     #endregion
                     *
                     * orderData.tempProdData = tempDisplayProduct;
                     * orderData.tempCustData = tempData;
                     *
                     * orderData.CreateOrder(jsonFilePathOrders, jsonFilePathCustomers, jsonFilePathProducts, selectProd, selectCust, citySelect, quant, dateString);
                     */
                    #endregion

                    #region DB Create

                    List <int> selectedProducts = new List <int>();

                    #region Display+Select Customer
                    while (allowedCustomer)
                    {
                        Console.Clear();

                        Console.Clear();
                        Console.WriteLine("Customers");

                        dataCustomer.DisplayCustomersDB();

                        Console.WriteLine("Please Select Customer: ");
                        selectCust = Int32.Parse(Console.ReadLine());
                        Log.Information("Selected Customer: {0}", selectCust);

                        if (selectCust > dataCustomer.CustomerCount)
                        {
                            allowedCustomer = true;
                            Console.WriteLine("Selected an Invalid Customer. Press any key to Try Again.");
                            Log.Information("Invalid Customer Selected [{0}]", selectCust);
                            Console.ReadKey();
                        }
                        else
                        {
                            allowedCustomer = false;
                        }
                    }
                    #endregion

                    #region Display+Select Product

                    Console.Clear();

                    LocationData locat = new LocationData();

                    while (allowedProduct)
                    {
                        Console.Clear();
                        Console.WriteLine("Products");

                        dataProduct.DisplayProductsDB();

                        Console.WriteLine("Please Select Product ID: ");
                        selectProd = Int32.Parse(Console.ReadLine());
                        Log.Information("Selected Product: {0}", selectProd);

                        if (selectProd > dataProduct.ProductCount)
                        {
                            allowedProduct = true;
                            Console.WriteLine("Selected an Invalid Product. Press any key to Try Again.");
                            Log.Information("Invalid Product Selected [{0}]", selectProd);
                            Console.ReadKey();
                        }
                        else
                        {
                            allowedProduct = false;
                        }
                    }

                    #region Display+Select Location
                    while (allowedCity)
                    {
                        Console.Clear();


                        locat.DisplayLocationsDB(selectProd);

                        Console.WriteLine("Select The Location: ");
                        citySelect = Int32.Parse(Console.ReadLine());
                        Log.Information("Selected Location [{0}]", citySelect);

                        /*//if (citySelect > locat.LocationCount)
                         * if (locat.LocationPresent.Contains(citySelect))
                         * {
                         *  allowedCity = true;
                         *  Console.WriteLine("Please Select a Valid City");
                         * }
                         * else
                         * {
                         *  allowedCity = false;
                         * }*/
                        allowedCity = false;     //TO BE FIXED
                    }
                    #endregion

                    //ADD CODE TO REDUCE QUANTITY FROM THE SELECTED STORE
                    #region  Enter Quantity

                    while (allowedQuant)
                    {
                        Console.Clear();
                        Console.WriteLine("Enter the Quantity: ");
                        quant = Int32.Parse(Console.ReadLine());
                        Log.Information("Selected Quantity: [{0}]", quant);

                        if (quant > locat.GetInventoryDB(citySelect, selectProd))
                        {
                            Console.WriteLine("Not Enough Copies left in the Inventory");
                            Console.WriteLine("Press Any Key To Try Again");
                            Log.Information("Invalid Quantity Entered. Your Quantity: [{0}]", quant);
                            Console.ReadKey();
                            allowedQuant = true;
                        }
                        else if (quant > 5)
                        {
                            Console.WriteLine("Enter a Valid Quantity [Order Limit: 5]");
                            Console.WriteLine("Press Any Key To Try Again");
                            Log.Information("Quantity Can Not Be More Than 5. Your Quantity: [{0}]", quant);
                            Console.ReadKey();
                            allowedQuant = true;
                        }
                        else
                        {
                            allowedQuant = false;
                        }
                    }
                    #endregion

                    selectedProducts.Add(selectProd);

                    #endregion

                    #region Enter Date
                    while (dateFormat == false)
                    {
                        try
                        {
                            Console.Clear();
                            Console.WriteLine("Enter Date and Time for the Order: ");
                            dateString = Console.ReadLine();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Date Not in Correct Format");
                            Console.WriteLine("Exception: {0}", ex);
                            Log.Information("Exception: {0}", ex);
                            caughException = true;
                        }
                        finally
                        {
                            if (caughException)
                            {
                                dateFormat = false;
                            }
                            else
                            {
                                dateFormat = true;
                            }
                        }
                    }
                    #endregion

                    orderData.CreateOrderDB(selectProd, selectCust, citySelect, quant, dateString);

                    #endregion

                    Console.Clear();
                    Console.WriteLine("Order Created");
                    Log.Information("Order Created");
                    Console.ReadKey();
                    break;

                case 2:

                    List <Order> displayOrder = new List <Order>();

                    displayOrder = orderData.DisplayOrders(jsonFilePathOrders);

                    Console.Clear();

                    #region SerializedOutput

                    /*
                     * Console.WriteLine("Orders");
                     * if (displayOrder.Count != 0)
                     * {
                     *  for (int i = 0; i < displayOrder.Count; i++)
                     *  {
                     *      for (int j = 0; j < displayOrder[i].product.location.Count; j++)
                     *      {
                     *          if (displayOrder[i].product.location[j].orderSelect == true)
                     *          {
                     *              storeLocation = displayOrder[i].product.location[j].City;
                     *          }
                     *      }
                     *      Console.WriteLine(" {0}. ID: {1} | Name: {2} | Location: {3} | Quantity: {4}", i + 1, displayOrder[i].OrderId, displayOrder[i].product.ProductName, storeLocation, displayOrder[i].orderQuantity, displayOrder[i].orderQuantity);
                     *  }
                     * }
                     * else
                     * {
                     *  Console.WriteLine("No Data Present");
                     * }
                     */
                    #endregion

                    #region DB Output

                    orderData.DisplayOrdersDB();

                    #endregion

                    Console.WriteLine("Press Any Key To Continue");
                    Console.ReadKey();
                    break;

                case 3:
                    Console.Clear();

                    int          customerId = 0;
                    CustomerData cust       = new CustomerData();
                    OrderData    dispOrder  = new OrderData();

                    Console.WriteLine("Customers");
                    cust.DisplayCustomersDB();
                    Console.WriteLine("Please Enter The Customer ID: ");
                    customerId = Int32.Parse(Console.ReadLine());

                    dispOrder.DisplayOrdersCustomerDB(customerId);

                    Console.WriteLine("Press Any Key To Continue");
                    Console.ReadKey();
                    break;

                case 4:
                    Console.Clear();

                    int          locationId = 0;
                    LocationData loc        = new LocationData();
                    OrderData    orderLoc   = new OrderData();

                    Console.WriteLine("Locations");
                    loc.DisplayAllLocationsDB();
                    Console.WriteLine("Please Enter The Location ID: ");
                    locationId = Int32.Parse(Console.ReadLine());

                    orderLoc.DisplayOrdersStoreDB(locationId);

                    Console.WriteLine("Press Any Key To Continue");
                    Console.ReadKey();
                    break;
                }
            } while (menuChoice < 5);
        }