public void changeProductInOrder() { Console.WriteLine(" -- Customers -- "); foreach (CustomerClass items in listCustomers) { Console.WriteLine("Customer number: {0} - Firstname: {1} - Lastname: {2} -", items.CustomerNo, items.FirstName, items.LastName); } Console.Write("Please provide a customerNo: "); string userCustomerSearchValue = Console.ReadLine(); Console.WriteLine(userCustomerSearchValue); List <Order> viewCustomerOrder = orderList.FindAll(x => x.customerInOrder.CustomerNo == userCustomerSearchValue); if (viewCustomerOrder.Count != 0) { Console.WriteLine("Orders for customer with number:" + userCustomerSearchValue); foreach (Order list in viewCustomerOrder) { Console.WriteLine(" -- Order -- " + list.orderNr); foreach (ProductsInOrder items in list.GetProductList()) { Console.WriteLine("You have {0} pieces of {1} with sku-nr {2} ", items.productQuantity, items.product.ItemName, items.product.Sku); } } Console.WriteLine("Please provide the order-nr of the order you want to change the product: "); Console.WriteLine("Order-nr#: "); int userInputOrderNr = int.Parse(Console.ReadLine()); Order orderToChange = orderList.Find(x => x.orderNr == userInputOrderNr); if (orderToChange != null) { List <ProductsInOrder> productsInOrder = orderToChange.GetProductList(); foreach (ProductsInOrder items in productsInOrder) { Console.WriteLine("Product number: {0} - Item name: {1} ", items.product.Sku, items.product.ItemName); Console.WriteLine("Product quantity: {0}", items.productQuantity); } Console.WriteLine("Wish product to you want to change?"); Console.WriteLine("Product-nr#"); try { int productSkuNr = int.Parse(Console.ReadLine()); ProductsInOrder productSearch = productsInOrder.Find(x => x.product.Sku == productSkuNr); if (productSearch != null) { Product getProductInStorage = storage.Find(x => x.Sku == productSkuNr); bool changeQuantity = true; do { try { Console.WriteLine("New quantity"); int productAdd = int.Parse(Console.ReadLine()); int totalQuantity = getProductInStorage.Quantity + productSearch.productQuantity; if (productAdd <= totalQuantity) { getProductInStorage.Quantity = getProductInStorage.Quantity + productSearch.productQuantity; productSearch.productQuantity = productAdd; getProductInStorage.Quantity = getProductInStorage.Quantity - productAdd; changeQuantity = false; Console.WriteLine("Changes made to the product-nr {0}", productSearch.product.Sku); } else { Console.WriteLine("We dont have that much"); changeQuantity = true; } } catch (FormatException) { Console.WriteLine("Bad Format"); changeQuantity = true; } } while (changeQuantity); } else { Console.WriteLine("That product dont exist in the order"); } } catch (FormatException) { Console.WriteLine("Bad Format"); } } else { Console.WriteLine("That order does not exist"); } Console.ReadKey(); } else { Console.WriteLine("That Customer does not exist or does not have orders"); Console.ReadKey(); } }
public void placeCustomerOrder() { List <ProductsInOrder> productsToBuy = new List <ProductsInOrder>(); bool truish = true; do { Console.WriteLine(" -- Customers -- "); foreach (CustomerClass items in listCustomers) { Console.WriteLine("Customer number: {0} - Firstname: {1} - Lastname: {2} -", items.CustomerNo, items.FirstName, items.LastName); } Console.WriteLine("Choose a customer or write Exit to return to: "); string userInputCustomer = Console.ReadLine(); if (userInputCustomer.ToUpper() == "EXIT") { truish = false; return; } CustomerClass customerSearch = listCustomers.Find(x => x.CustomerNo == userInputCustomer); if (customerSearch != null) { bool addItem = true; do { try { bool haveProduct = false; Console.WriteLine("Currently, we have these items in stock. Write down the items sku number to begin a purchase "); foreach (Product items in storage) { Console.WriteLine("Item number: {0} - Name: {1} - Price: {2} - Quantity: {3} ", items.Sku, items.ItemName, items.Price, items.Quantity); } Console.Write("Choose a product by item number: "); int userInputsku = Convert.ToInt32(Console.ReadLine()); Product productSearch = storage.Find(x => x.Sku == userInputsku); if (productSearch != null) { foreach (ProductsInOrder items in productsToBuy) { if (items.product.Sku == userInputsku) { Console.WriteLine("You already choosen that product"); Console.ReadKey(); haveProduct = true; } } if (!haveProduct) { Console.WriteLine("Number of found items: {0}, how many would you like to purchase?", productSearch.Quantity); Console.Write("# "); int NoOfPurchaseOrders = Convert.ToInt32(Console.ReadLine()); if (productSearch.Quantity >= NoOfPurchaseOrders && !String.IsNullOrEmpty(NoOfPurchaseOrders.ToString())) { ProductsInOrder newProduct = new ProductsInOrder(productSearch, NoOfPurchaseOrders); productsToBuy.Add(newProduct); productSearch.Quantity = productSearch.Quantity - NoOfPurchaseOrders; Console.WriteLine("Do you want to add a new product - Y/N"); string inputYesOrNo = Console.ReadLine(); if (inputYesOrNo.ToUpper() == "Y") { addItem = true; } else { Order order = new Order(productsToBuy, customerSearch); orderList.Add(order); Console.WriteLine("Congratulations! your order was successfully processed"); Console.ReadKey(); addItem = false; truish = false; } } else { Console.WriteLine("Yo have choosen to many items"); Console.ReadKey(); } } else { Console.WriteLine("If you want to end and add order write END"); string AddOrderEnd = Console.ReadLine(); if (AddOrderEnd.ToUpper() == "END") { Order order = new Order(productsToBuy, customerSearch); orderList.Add(order); Console.WriteLine("Congratulations! your order was successfully processed"); Console.ReadKey(); addItem = false; truish = false; } } } else { Console.WriteLine("That item do not exist!"); Console.ReadKey(); } } catch (FormatException) { Console.WriteLine("Bad Format"); addItem = true; } } while (addItem); } else { Console.WriteLine("That customer do not exist!"); Console.ReadKey(); } } while (truish); }