public IActionResult ConfirmOrder(OrderIndexVM orderIndexVM) { string drinkOrderString = TempData["DrinkOrders"].ToString(); orderIndexVM.DrinkOrders = JsonConvert.DeserializeObject <List <DrinkOrderVM> >(drinkOrderString); var customer = _customerBL.GetCustomerByID(orderIndexVM.CustomerID); if (customer != null) { orderIndexVM.CustomerName = customer.Name; } var location = _locationBL.GetSpecifiedLocation(orderIndexVM.LocationID); if (location != null) { orderIndexVM.LocationName = location.LocationName; orderIndexVM.State = location.State; } orderIndexVM.Total = GetTotal(orderIndexVM.DrinkOrders); return(View(orderIndexVM)); }
public void GetStores() { foreach (var element in _locationBL.GetLocations()) { Console.WriteLine(element.ToString()); } Console.WriteLine("Enter a Store Code: "); int storeCode = int.Parse(Console.ReadLine()); Location specifiedLocation = _locationBL.GetSpecifiedLocation(storeCode); if (specifiedLocation == null) { Console.WriteLine("Invalid code."); } else { Console.WriteLine($"{specifiedLocation.LocationName} Inventory: "); foreach (Drink element in _drinkBL.GetDrinksByLocation(storeCode)) { Console.WriteLine(element.DrinkName.ToString()); //not sure if this will work ^^^^^ } Order newOrder = new Order(); bool shop = true; List <Drink> drinkCart = new List <Drink>(); List <int> quantityInCart = new List <int>(); decimal total = 0.0m; do { Console.WriteLine("Select Drink to add to your order"); Console.WriteLine("Type 'Submit' when you're finished."); Console.WriteLine("If you wish to cancel, type 'Cancel'"); Console.WriteLine("Selection: "); string selection = Console.ReadLine(); if (selection == "cancel" || selection == "Cancel") { shop = false; } else if (selection == "submit" || selection == "Submit") { newOrder.Total = total; newOrder.Location = specifiedLocation; Customer customerOrder = FindCustomer(); if (customerOrder == null) { Console.WriteLine("cannot find customer"); } else { newOrder.Customer = customerOrder; } _orderBL.AddOrder(newOrder); } }while (shop); } }
public void PlaceOrder() { Console.Clear(); AsciiHeader.AsciiHead(); Customer customer = new Customer(); customerSearch.Start(customer); //we have the customer //we need the location next Boolean stay = true; Location location = new Location(); while (stay) { Console.Clear(); AsciiHeader.AsciiHead(); Console.WriteLine("Please select customer store location"); Console.WriteLine("[0] Tampa"); Console.WriteLine("[1] Orlando"); string userInput = Console.ReadLine(); switch (userInput) { case "0": location = _locationBL.GetSpecifiedLocation(20000); stay = false; break; case "1": location = _locationBL.GetSpecifiedLocation(20001); stay = false; break; default: Console.WriteLine("Not a valid menu option!"); break; } //Console.WriteLine(location); } Cart cart = new Cart(); //Console.WriteLine(customer); //now, with both a customer and location, we can create a cart OR call a cart //if the customer's cart already exists, it will use that cart try { cart = _cartBL.FindCart(customer.CustomerID); } catch (Exception ex) { Log.Error(ex, "Something went wrong"); } //before we start assigning products to carts, we need to know our inventory ID list to pass into the product search List <Inventory> inventories = _inventoryBL.GetInventory(); List <Inventory> specificInventories = new List <Inventory>(); foreach (Inventory i in inventories) { if (i.InventoryLocation == location.LocationID) { specificInventories.Add(i); } } //THIS is where we would want to call our product search menu // we want to basically run this, then on complete, create a new cartproduct object // we can check against inventory amount here!!! try { productSearch.Start(location, cart.CartID, inventories); } catch (System.ArgumentOutOfRangeException ex) { Log.Error(ex, "Someone tried to order a product that didn't exist"); Console.WriteLine("Sorry, the requested product does not exist at your location.\nPlease try again."); Console.WriteLine("Press enter to continue"); Console.ReadLine(); productSearch.Start(location, cart.CartID, inventories); } List <CartProducts> cartProducts = _cartProductsBL.FindCartProducts(cart.CartID); decimal costTotal = 0; LineSeparator line = new LineSeparator(); Console.WriteLine("Please confirm your order for processing:"); Console.WriteLine("Products Ordered:"); foreach (CartProducts x in cartProducts) { Product currentProduct = _productBL.GetProductByID(x.ProductID); decimal currentProductCost = currentProduct.ProductPrice.Value * x.ProductCount.Value; costTotal = costTotal + currentProductCost; line.LineSeparate(); Console.WriteLine($"| Product Name: {currentProduct.ProductName} | Product Quantity: {x.ProductCount} | Individual Product Cost: {currentProductCost}"); line.LineSeparate(); } line.LineSeparate(); Console.WriteLine($"| Total Cost: {costTotal}"); Console.WriteLine("Is this order accurate?"); Console.WriteLine("[0] Yes"); Console.WriteLine("[1] No"); string confirmationInput; confirmationInput = Console.ReadLine(); bool stayConfirm = true; bool processOrder = true; while (stayConfirm) { switch (confirmationInput) { case "0": Console.WriteLine("Fantastic! Please press enter to begin order processing."); Console.ReadLine(); processOrder = true; stayConfirm = false; break; case "1": Console.WriteLine("Okay, please update your order as necessary and return to this confirmation page."); Console.WriteLine("Please press enter."); Console.ReadLine(); processOrder = false; stayConfirm = false; break; default: Console.WriteLine("Not a valid menu option!"); break; } } if (processOrder == true) { //time to process the order Order finalizedOrder = new Order(); finalizedOrder.CartID = cart.CartID; finalizedOrder.Customer = customer; finalizedOrder.CustomerID = customer.CustomerID; finalizedOrder.LocationID = location.LocationID; finalizedOrder.OrderDate = DateTime.Now; _orderBL.AddOrder(finalizedOrder); //we will need to retrieve the order that was just added for it's ID! //this will let us process what items were included in the order Order orderForItemsProcessing = _orderBL.GetSpecifiedOrder(finalizedOrder.OrderDate); //create a new order item list List <OrderItem> orderItems = new List <OrderItem>(); //add each new orderItem to our database foreach (CartProducts p in cartProducts) { OrderItem orderProcessing = new OrderItem { OrderItemsQuantity = p.ProductCount, OrderID = orderForItemsProcessing.OrderID, productID = p.ProductID, }; _orderItemsBL.AddOrderItem(orderProcessing); } //flush the cart once the order is complete. foreach (CartProducts cartprod in cartProducts) { _cartProductsBL.RemoveCartProducts(cartprod); } Log.Information("Order placed successfully"); Console.WriteLine("Order placed successfully!"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); Console.Clear(); } //we now have EVERYTHING ready (I think) //List<OrderItem> orderItemsToConfirm = _orderItemsBL.GetOrderItems(orderForItemsProcessing.OrderID); //now that we have a cart, we need to find products //then add them to a new cartproducts table so the cart //can reference them //we will call cartproduct BL to create a new cartproduct //every time something is added to the inventory. //then, we can return a list of cartproducts after? //then create an order when products/total are ready! }