public Library.DataBase GetOrder(int id) { using var context = new StoreDBContext(_contextOptions); var dbOrderHitory = context.CustomerOrders.Include(c => c.ProductOrdereds) .ThenInclude(c => c.Product) .ThenInclude(c => c.Prices); var db = new Library.DataBase(new Library.Store(id)); foreach (var orders in dbOrderHitory) { if (orders.TransactionNumber == id) { var x = orders.TransactionTime.ToString(); Library.Order order = new Library.Order(id, orders.StoreId, orders.CustomerId, x); foreach (var item in orders.ProductOrdereds) { var price = item.Product.Prices.ToList(); var tPrice = price[0].Price1; order.addItem(new Library.Product(item.ProductId, item.Product.Name, (int)item.Quantity, (double)tPrice)); } db.AddOrder(order); } } return(db); }
/// <summary> /// Get Order History of Custoemr /// </summary> /// <param name="id"></param> /// <returns> Returns a Database with the history of cutsomers</returns> public Library.DataBase GetOrderHistoryOfCustomer(int id) { using var context = new StoreDBContext(_contextOptions); var dbOrderHitory = context.CustomerOrders.Include(c => c.Customer); var customer = new Library.DataBase(new Library.Customer(id)); foreach (var order in dbOrderHitory) { if (order.CustomerId == id) { customer.AddOrder(new Order(order.TransactionNumber, id, order.CustomerId, order.Customer.FirstName, order.Customer.LastName, order.TransactionTime.ToString())); } } return(customer); }
/// <summary> /// Create an order. using the databassed in. /// </summary> /// <param name="db"></param> public int AddCustomerOrder(Library.DataBase db) { using var context = new StoreDBContext(_contextOptions); Order order = db.Stores[0].Order[0]; // pass in all the values in Customer Order DataModel.CustomerOrder newOrder = new DataModel.CustomerOrder() { StoreId = order.StoreId, CustomerId = order.CustomerId }; // add the order and save context.Add(newOrder); context.SaveChanges(); int id = newOrder.TransactionNumber; // Grab the transacction Number AddCustomerItems(id, order); return(id); }
public static void makeOrder() { // get all of the customers List <Customer> customers = SqlDb.GetAllCustomers(); Library.DataBase db = new Library.DataBase(customers); // Print a list of the customers db.printCustomers(); Console.WriteLine("Enter a Customer ID"); string customerId = Console.ReadLine(); // select your customer Customer customer = SearchCustomers.customerSearchID(customers, customerId); // don'd continue unless the person actually put in a correct customer id. if (customer.isValid()) { // get the store information uiPrintAllStores(); Console.WriteLine("Choose a Store: "); int StoreChoiceCheck = 0; string StoreChoice = Console.ReadLine(); Int32.TryParse(StoreChoice, out StoreChoiceCheck); Store store = SqlDb.GetInventory(StoreChoiceCheck); if (store.hasInventory()) { // add store to our database db.AddStore(store); // making order Order newOrder = new Order(StoreChoiceCheck, customer.CustomerId); store.printInventory(); Console.WriteLine("Starting order press (q) to quit"); string choice = ""; while (choice.ToLower() != "q") { Console.WriteLine("Choose a Product"); choice = Console.ReadLine(); if (choice != "q" && choice != "q") { int choiceCheck = 0; int.TryParse(choice, out choiceCheck); // if user actually inserts a number if (choiceCheck != 0) { // using the only store in the database grab the product from the inventory var item = db[0].getInventory(choiceCheck); //give user a chance to escape one more time string quantity = ""; if (quantity != "q" && choice != "q" && item.ProductID != 0) { Console.WriteLine("Choose a quantity: "); quantity = Console.ReadLine(); int quantityCheck = 0; int.TryParse(quantity, out quantityCheck); if (quantityCheck != 0) { newOrder.addItem(item, quantityCheck); Console.WriteLine("Your Total So Far is " + newOrder.Cost); } else { Console.WriteLine("Quanity Must be greater than 0"); } } } } db.Stores[0].AddOrder(newOrder); } // if we have items in our order submit to database if (newOrder.hasItems()) { int TransactionNumber = SqlDb.AddCustomerOrder(db); Console.WriteLine(newOrder.newOrderString(TransactionNumber)); } } } }