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"); } }
public void UpdateItem() { foreach (var item in _locationBL.GetLocations()) { Console.WriteLine(item.ToString()); } bool foundLoc = false; Location loc = null; int option; do { try { Console.WriteLine("Enter location code for store to update inventory:"); option = int.Parse(Console.ReadLine()); loc = _locationBL.GetSpecificLocation(option); if (loc == null) { Console.WriteLine("Invalid location id, please search again"); } else { foundLoc = true; } } catch (FormatException) { Console.WriteLine("Invalid store code, make sure to enter a number"); Log.Error("Incorrect input for store id"); } }while(!foundLoc); foreach (var item in _itemBL.GetItemsByLocation(loc.LocationID)) { Console.WriteLine($"Item ID: {item.ItemID}"); Console.WriteLine(item.Product.ToString()); Console.WriteLine(item.ToString()); } try { Console.WriteLine("Select Item ID to replenish inventory:"); int choice = int.Parse(Console.ReadLine()); Item item2BUpdated = _itemBL.GetItemByID(choice); if (item2BUpdated == null) { Console.WriteLine("Error - did not select a valid ItemID"); } else { Console.WriteLine($"Enter new quantity for {item2BUpdated.Product.ProductName} at {item2BUpdated.Location.LocationName}:"); int q = int.Parse(Console.ReadLine()); _itemBL.UpdateItem(item2BUpdated, q); Console.WriteLine("Successfully updated!"); Log.Information($"Inventory {item2BUpdated.Product.ProductName} updated to {q}"); } Console.WriteLine(); } catch (FormatException) { Console.WriteLine("Error - incorrect entry for item id"); Log.Error("Incorrect entry for when selecting item id for updating inventory"); } }