private DtoOrderResponse FillOrderResponse(OrderResponse dbResponse) { if (dbResponse == null) { return(null); } var dtoResponse = dbResponse.ToDTO(); dtoResponse.DrugStore = StoreQueries.Get(dbResponse.DrugStore_id); dtoResponse.SkuReplys = GetSkuReplay(dtoResponse.Id); return(dtoResponse); }
public void viewAllStores() { Console.Clear(); StoreQueries storeHistory = new StoreQueries(); var stores = storeHistory.getStores(); Console.WriteLine("ID\tLocation"); foreach (var s in stores) { Console.WriteLine($"{s.StoreID}\t{s.Location}"); } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); }
public void showOrderHistory() { Console.Clear(); StoreQueries storeHistory = new StoreQueries(); var stores = storeHistory.getStores(); Console.WriteLine("ID\tLocation"); foreach (var s in stores) { Console.WriteLine($"{s.StoreID}\t{s.Location}"); } Console.WriteLine("Please Enter the ID of the Store you would like to view History of"); string input = Console.ReadLine(); int.TryParse(input, out int result); if (storeHistory.existsStore(result)) { var orders = storeHistory.getHistory(result); var loc = storeHistory.getLocation(result); if (orders.Count() == 0) { Console.WriteLine($"No orders has been made to {loc} "); } else { Console.WriteLine($"Order history for {result} {loc}"); Console.WriteLine("Customer\tProduct\t\tQuantity\tTotal\t\tTime"); foreach (var o in orders) { double price = o.Product.Price * o.Count; Console.WriteLine($"{o.Customer.FirstName} {o.Customer.LastName}\t" + $"{o.Product.Name}\t{o.Count}" + $"\t\t${price}\t\t{o.Time}"); } } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); } }
public void showStoreProducts() { int storeID = 0; StoreQueries stores = new StoreQueries(); #region get storeID Console.WriteLine("Please enter a StoreID for the location you would like to place your order at"); string input = Console.ReadLine(); bool invalid = true; int result; while (invalid) { if (!int.TryParse(input, out result) || !stores.existsStore(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { storeID = result; invalid = false; } } #endregion #region display products ProductQueries products = new ProductQueries(); var productList = products.getProducts(storeID); Console.Clear(); Console.WriteLine("ID\tStore\t\tName\t\tInventory\tPrice"); foreach (var p in productList) { Console.WriteLine($"{p.ProductID}\t{p.Store.Location}\t{p.Name}" + $"\t{p.Inventory}\t\t{p.Price}"); } #endregion Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); }
/// <summary> /// input/output for the process of displaying an store's history with all /// the validation taking place along the way and finally displaying /// the history of the store meeting the input parameters. /// </summary> public void DisplayStoreHistory() { StoreQueries checkStore = new StoreQueries(); OrderCreation checkNum = new OrderCreation(); // get and display stores to pick from var stores = checkStore.GetStores(); Console.WriteLine("ID\tLocation"); foreach (var s in stores) { Console.WriteLine($"{s.StoreID}\t{s.Location}"); } Console.WriteLine("Please enter an ID from above for the store location you would like to see."); int storeID; do { string input = Console.ReadLine(); if (input == "cancel") { return; } // check if input is an int while (!checkNum.IsValidNum(input)) { Console.WriteLine("Invalid ID number, please enter another."); input = Console.ReadLine(); if (input == "cancel") { return; } } int id = checkNum.StringToInt(input); // check if there is a store with the given ID if (checkStore.IsValidStoreID(id)) { storeID = id; } else { Console.WriteLine("There is no store with this ID, please enter another."); storeID = 0; } } while (storeID == 0); // repeat if no store with that ID var storeHistory = checkStore.GetStoreHistory(storeID); var storeLocation = checkStore.GetStoreLocation(storeID); // get and display all the order history for that location if (storeHistory.Count() == 0) { Console.WriteLine($"As of now, no orders have been made from {storeLocation}"); } else { Console.WriteLine($"Order history for {storeLocation}"); Console.WriteLine("Customer\tProduct\t\tQuantity\tTotal\t\tTimestamp"); foreach (var o in storeHistory) { double price = o.Product.Price * o.Quantity; Console.WriteLine($"{o.Customer.FirstName} {o.Customer.LastName}\t" + $"{o.Product.ProductName}\t{o.Quantity}" + $"\t\t${price}\t\t{o.Timestamp}"); } } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); }
/// <summary> /// input/output for the process of adding a new order with all /// the validation taking place along the way and finally adding /// a new order with the given information. /// </summary> public void AddNewOrder() { // declare new instance(s) using (StoreApp_DbContext db = new StoreApp_DbContext()) { OrderCreation createOrder = new OrderCreation(); CustomerQueries checkCustomer = new CustomerQueries(); Order newOrder = new Order(); Console.WriteLine("Please enter the customerID of your Customer placing an order."); do { string input = Console.ReadLine(); if (input == "cancel") { return; } // check if input is an int while (!createOrder.IsValidNum(input)) { Console.WriteLine("Invalid customerID number, please enter another."); input = Console.ReadLine(); if (input == "cancel") { return; } } // check if there is a customer with the inputted ID int id = createOrder.StringToInt(input); if (checkCustomer.IsValidCustomerID(id)) { newOrder.CustomerID = id; } else { Console.WriteLine("There is no Customer with this ID, please enter another."); newOrder.CustomerID = 0; } } while (newOrder.CustomerID == 0); // repeat if there is no customer with the ID // display all the available products ProductQueries checkProducts = new ProductQueries(); var products = checkProducts.GetProducts(); Console.WriteLine("Here are all the available products:"); Console.WriteLine("ID\tStore\t\tName\t\tInventory\tPrice"); foreach (var p in products) { Console.WriteLine($"{p.ProductID}\t{p.Store.Location}\t{p.ProductName}" + $"\t{p.Inventory}\t\t{p.Price}"); } bool multipleProducts; int productCount = 0; do { Console.WriteLine("Please enter the ID of the product being ordered"); do { string input = Console.ReadLine(); if (input == "cancel") { return; } // check if input is an int while (!createOrder.IsValidNum(input)) { Console.WriteLine("Invalid product ID number, please enter another."); input = Console.ReadLine(); if (input == "cancel") { return; } } int id = createOrder.StringToInt(input); // check if there is a product with the inputted ID if (checkProducts.IsValidProductID(id)) { newOrder.ProductID = id; } else { Console.WriteLine("There is no product with this ID or there is none left, please enter another."); newOrder.ProductID = 0; } } while (newOrder.ProductID == 0); // repeat if no product with that ID var product = checkProducts.GetProductName(newOrder.ProductID); Console.WriteLine($"For buying, specify the number of {product.ProductName}"); do { string input = Console.ReadLine(); if (input == "cancel") { return; } // check if input is an int while (!createOrder.IsValidNum(input)) { Console.WriteLine("Invalid amount, please enter another."); input = Console.ReadLine(); if (input == "cancel") { return; } } int amount = createOrder.StringToInt(input); // check if the inventory is high enough for given amount if (amount == 0) { Console.WriteLine("Please specify an amount"); } else if (createOrder.IsUnreasonableQuantity(amount)) { // if the amount requested is unreasonable (>=10) Console.WriteLine($"{amount} is an unreasonable amount of {product.ProductName}"); newOrder.Quantity = 0; } else if (checkProducts.IsValidProductQuantity(amount, newOrder.ProductID)) { // if there is enough product and it is reasonable newOrder.Quantity = amount; } else { Console.WriteLine($"There is not {amount} available at this store, please enter another amount."); newOrder.Quantity = 0; } } while (newOrder.Quantity == 0); // repeat if not enough product or unreasonable Console.WriteLine("Would you like to include another product in this order (yes or no)?"); string addProduct = Console.ReadLine(); if (addProduct == "cancel") { return; } // check if they are saying yes or no to extra product while (addProduct != "yes" && addProduct != "no") { Console.WriteLine("Please pick put in one of the two"); addProduct = Console.ReadLine(); if (addProduct == "cancel") { return; } } if (addProduct == "yes") { multipleProducts = true; } else { multipleProducts = false; } productCount++; if (productCount == 1) { // keep same timestamp for multiple product order newOrder.Timestamp = createOrder.GetTimeStamp(); } db.Add <Order>(newOrder); db.SaveChanges(); StoreQueries updateStore = new StoreQueries(); updateStore.UpdateInventory(newOrder); newOrder.OrderID++; } while (multipleProducts); // go back if they wanted another product Console.WriteLine("Order successfully placed! Hit enter to go back to menu."); Console.ReadLine(); } }
public void placeOrder() { using (P0DbContext db = new P0DbContext()){ int storeID = 0; Order newOrder = new Order(); CustomerQueries customers = new CustomerQueries(); StoreQueries stores = new StoreQueries(); #region get storeID Console.WriteLine("Please enter a StoreID for the location you would like to place your order at"); string input = Console.ReadLine(); bool invalid = true; int result; while (invalid) { if (!int.TryParse(input, out result) || !stores.existsStore(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { storeID = result; invalid = false; } } #endregion #region get customerID Console.WriteLine("Please enter the CustomerID of whose placing the order"); input = Console.ReadLine(); invalid = true; while (invalid) { if (!int.TryParse(input, out result) || !customers.existsCustomer(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { newOrder.CustomerID = result; invalid = false; } } #endregion #region display products ProductQueries products = new ProductQueries(); var productList = products.getProducts(storeID); Console.Clear(); Console.WriteLine("ID\tStore\t\tName\t\tInventory\tPrice"); foreach (var p in productList) { Console.WriteLine($"{p.ProductID}\t{p.Store.Location}\t{p.Name}" + $"\t{p.Inventory}\t\t{p.Price}"); } #endregion bool ordering = true; int time = 0; while (ordering) { #region productID Console.WriteLine("Please enter the productID what you want"); input = Console.ReadLine(); invalid = true; while (invalid) { if (!int.TryParse(input, out result) || !products.existsProduct(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { newOrder.ProductID = result; invalid = false; } } #endregion #region count Console.WriteLine("Please enter the amount that you want"); input = Console.ReadLine(); invalid = true; while (invalid) { if (!int.TryParse(input, out result) || !products.checkCount(newOrder.ProductID, result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { newOrder.Count = result; invalid = false; } } #endregion #region keep ordering do { Console.WriteLine("Would you like to keep ordering? Yes : No"); input = Console.ReadLine(); } while (!(input == "Yes" || input == "No")); if (input == "Yes") { ordering = true; } else { ordering = false; } time++; if (time == 1) { newOrder.Time = DateTime.Now; } db.Add <Order>(newOrder); db.SaveChanges(); StoreQueries update = new StoreQueries(); update.placeOrder(newOrder); newOrder.OrderID++; #endregion } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); } }