public void CheckStoreProductReturnsFalseIfNoProduct() { using var context = new StoreApplicationContext(options); BusinessLogic.Objects.Store testStore = new BusinessLogic.Objects.Store(); Assert.False(testStore.storeInventory.CheckIfProductListNotNull()); }
public void GetManagerReturnsProperValues(int testID) { using var context = new StoreApplicationContext(options); BusinessLogic.Objects.Manager testManager = new BusinessLogic.Objects.Manager(); testManager = DBRHandler.GetManagerDataFromID(testID, context); Assert.True(testManager.CheckIfManagerNull()); }
public void CheckStoreDataReturnProperValues(int testID) { using var context = new StoreApplicationContext(options); BusinessLogic.Objects.Store testStore = new BusinessLogic.Objects.Store(); testStore = DBRHandler.GetStoreFromStoreNumber(testID, context); Assert.True(testStore.CheckStoreNotNull()); }
public void CheckStoreProductReturnsProperValues(int testID) { using var context = new StoreApplicationContext(options); BusinessLogic.Objects.Store testStore = new BusinessLogic.Objects.Store(); testStore = DBRHandler.GetStoreFromStoreNumber(testID, context); testStore.storeInventory = DBRHandler.GetStoreInventoryByStoreNumber(testID, context); Assert.True(testStore.storeInventory.CheckIfProductListNotNull()); }
/// <summary> /// Gets the customer ID of a newly created customer /// </summary> /// <param name="context"></param> /// <returns></returns> public int GetNewCustomerID(StoreApplicationContext context) { int NewCustID = 0; foreach (Entities.Customer cust in context.Customer) { NewCustID = cust.CustomerId; } return(NewCustID); }
/// <summary> /// Inputs an order into the Order table. Does NOT input products. /// </summary> /// <param name="BLOrder"></param> /// <param name="context"></param> public void InputOrder(Order BLOrder, StoreApplicationContext context) { try { context.Orders.Add(ParseHandler.LogicOrderToContextOrder(BLOrder)); context.SaveChanges(); } catch (Microsoft.EntityFrameworkCore.DbUpdateException e) { Console.WriteLine("Something went wrong inputting order: " + e); } }
/// <summary> /// Given a context, it returns all the customer data in the database /// </summary> /// <param name="context"></param> /// <returns></returns> public List <StoreApp.BusinessLogic.Objects.Customer> GetAllCustomerData(StoreApplicationContext context) { List <StoreApp.BusinessLogic.Objects.Customer> listOfCustomerData = new List <StoreApp.BusinessLogic.Objects.Customer>(); foreach (StoreApp.DataLibrary.Entities.Customer customerInDB in context.Customer) { StoreApp.BusinessLogic.Objects.Customer retrievedCustomer = new StoreApp.BusinessLogic.Objects.Customer(); listOfCustomerData.Add(retrievedCustomer); } return(listOfCustomerData); }
public void CheckIfOrderDataReturnsProperIDs(int testID) { using var context = new StoreApplicationContext(options); List <BusinessLogic.Objects.Order> testListOrder = new List <Order>(); testListOrder = DBRHandler.GetListOfOrdersByCustomerID(testID, context); foreach (BusinessLogic.Objects.Order testOrder in testListOrder) { if (testOrder.customer.customerID == testID) { Assert.True(testOrder.CheckOrderHasIDs()); } } }
/// <summary> /// Given a manager ID and a database context, returns manager data into a BusinessLibrary manager object /// </summary> /// <param name="managerID"></param> /// <param name="context"></param> /// <returns></returns> public BusinessLogic.Objects.Manager GetManagerDataFromID(int managerID, StoreApplicationContext context) { try { foreach (StoreApp.DataLibrary.Entities.Manager man in context.Manager) { if (man.ManagerId == managerID) { return(parser.ContextManagerToLogicManager(man)); } } return(null); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
public List <Order> GetListOfOrdersFromStoreNumber(int storeNumber, StoreApplicationContext context) { List <BusinessLogic.Objects.Order> BLListOrders = new List <Order>(); foreach (Entities.Orders CTXOrder in context.Orders) { BLListOrders.Add(parser.ContextOrderToLogicOrder(CTXOrder)); } foreach (BusinessLogic.Objects.Order BLOrder in BLListOrders) { foreach (Entities.OrderProduct CTXOrdProd in context.OrderProduct) { if (BLOrder.orderID == CTXOrdProd.OrderId) { BLOrder.customerProductList.Add(parser.ContextOrderProductToLogicProduct(CTXOrdProd)); } } } return(BLListOrders); }
/// <summary> /// Gets a business logic version of a store given a store number and a Database context /// </summary> /// <param name="storeNum"></param> /// <param name="context"></param> /// <returns></returns> public BusinessLogic.Objects.Store GetStoreFromStoreNumber(int storeNum, StoreApplicationContext context) { BusinessLogic.Objects.Store BLStore = new BusinessLogic.Objects.Store(); try { foreach (StoreApp.DataLibrary.Entities.Store storeLoc in context.Store) { if (storeLoc.StoreNumber == storeNum) { BLStore = parser.ContextStoreToLogicStore(storeLoc); } } return(BLStore); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
/// <summary> /// Gets the inventory of a store given a store number and a database context /// </summary> /// <param name="storeNumber"></param> /// <param name="context"></param> /// <returns></returns> public Inventory GetStoreInventoryByStoreNumber(int storeNumber, StoreApplicationContext context) { Inventory BLInventory = new Inventory(); BusinessLogic.Objects.Product BLProduct = new BusinessLogic.Objects.Product(); try { foreach (Entities.InventoryProduct prod in context.InventoryProduct) { if (prod.StoreNumber == storeNumber) { BLProduct = parser.ContextInventoryProductToLogicProduct(prod); BLInventory.productData.Add(BLProduct); BLProduct = new BusinessLogic.Objects.Product(); } else { } } foreach (BusinessLogic.Objects.Product prod in BLInventory.productData) { foreach (Entities.Product entProd in context.Product) { if (prod.productTypeID == entProd.ProductTypeId) { prod.name = entProd.ProductName; } } } return(BLInventory); } catch (Exception e) { Console.WriteLine("Unable to get the list of store inventory items: " + e.Message); return(null); } }
public StoreRepository(StoreApplicationContext dbContext) =>
/// <summary> /// Gets a list of Business Logic orders under a valid customer ID and a database context /// </summary> /// <param name="custID"></param> /// <param name="context"></param> /// <returns></returns> public List <StoreApp.BusinessLogic.Objects.Order> GetListOfOrdersByCustomerID(int custID, StoreApplicationContext context) { List <Order> listToBeReturned = new List <Order>(); try { foreach (Entities.Orders CTXOrder in context.Orders) { if (CTXOrder.CustomerId == custID) { listToBeReturned.Add(parser.ContextOrderToLogicOrder(CTXOrder)); } } return(listToBeReturned); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
/// <summary> /// Gets a list of customer data using an inputted customerID and a Database context /// </summary> /// <param name="customerID"></param> /// <param name="context"></param> /// <returns></returns> public StoreApp.BusinessLogic.Objects.Customer GetCustomerDataFromID(int customerID, StoreApplicationContext context) { //Some code to retrieve a list of customer data try { foreach (Entities.Customer cust in context.Customer) { if (cust.CustomerId == customerID) { return(parser.ContextCustomerToLogicCustomer(cust)); } } return(null); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
/// <summary> /// Gets a list of BusinessLogic products using a BusinessLogic Order and a database context /// </summary> /// <param name="BLOrder"></param> /// <param name="context"></param> /// <returns></returns> public List <BusinessLogic.Objects.Product> GetListOrderProductByOrderID(Order BLOrder, StoreApplicationContext context) { List <BusinessLogic.Objects.Product> BLProdList = new List <BusinessLogic.Objects.Product>(); foreach (Entities.OrderProduct CTXOrdProd in context.OrderProduct) { if (CTXOrdProd.OrderId == BLOrder.orderID) { BLProdList.Add(parser.ContextOrderProductToLogicProduct(CTXOrdProd)); } } foreach (BusinessLogic.Objects.Product BLProd in BLProdList) { foreach (Entities.Product CTXProd in context.Product) { //If the product in the list is equal to a product ID on the product table, parse to fill name if (BLProd.productTypeID == CTXProd.ProductTypeId) { BLProd.name = CTXProd.ProductName; } } } return(BLProdList); }
/// <summary> /// Deletes a customer from the database /// </summary> /// <param name="customerID"></param> /// <param name="context"></param> public void DeleteCustomerByID(int customerID, StoreApplicationContext context) { //Some code that removes customer from the DB given an ID //context.Customer.Remove(); }
/// <summary> /// Adds new customer data to the Customer database table given a Business Logic customer object and a database context /// </summary> /// <param name="BLCustomer"></param> /// <param name="context"></param> public void AddNewCustomerData(StoreApp.BusinessLogic.Objects.Customer BLCustomer, StoreApplicationContext context) { //Some code to input customer data to the DB try { context.Customer.Add(ParseHandler.LogicCustomerToContextCustomer(BLCustomer)); context.SaveChanges(); } catch (Exception e) { Console.WriteLine("Failed to put the customer into the database: " + e.Message); } }
/// <summary> /// Inputs the order products into the OrderProduct table under an order ID given a Business Logic Order, an order ID, and a database context /// </summary> /// <param name="BLOrder"></param> /// <param name="orderID"></param> /// <param name="context"></param> public void InputOrderProduct(BusinessLogic.Objects.Order BLOrder, int orderID, StoreApplicationContext context) { try { foreach (BusinessLogic.Objects.Product BLProd in BLOrder.customerProductList) { context.OrderProduct.Add(ParseHandler.LogicProductToContextOrderProduct(BLOrder, orderID, BLProd)); } context.SaveChanges(); } catch (Exception e) { Console.WriteLine("Something went wrong inputting the OrderProduct for the Order: " + e.Message); return; } }
public void ModifyInventoryGivenOrder(Order inputOrder, BusinessLogic.Objects.Store inputStore, StoreApplicationContext context) { }
public static void InputWholeOrderAndUpdateInventory(Order inputOrder, BusinessLogic.Objects.Store inputStore, StoreApplicationContext context) { DBIHandler.InputOrder(inputOrder, context); DBIHandler.InputOrderProduct(inputOrder, context.Orders.Count(), context); }
public RetrieveDatabaseHandler(StoreApplicationContext context) { _context = context; }
/// <summary> /// Gets the information of a business logic store given an orderID that it came from and a database context /// </summary> /// <param name="orderID"></param> /// <param name="context"></param> /// <returns></returns> public BusinessLogic.Objects.Store GetStoreInformationFromOrderNumber(int orderID, StoreApplicationContext context) { BusinessLogic.Objects.Store BLStore = new BusinessLogic.Objects.Store(); try { foreach (Entities.OrderProduct CTXOrdProd in context.OrderProduct) { if (CTXOrdProd.OrderId == orderID) { BLStore.storeNumber = CTXOrdProd.StoreNumber; } } foreach (Entities.Store CTXStore in context.Store) { if (CTXStore.StoreNumber == BLStore.storeNumber) { BLStore = parser.ContextStoreToLogicStore(CTXStore); } } return(BLStore); } catch (Exception e) { Console.WriteLine("Unable to get store information from order: " + e.Message); return(null); } }
static void Main(string[] args) { using (StoreApplicationContext dbContext = CreateDbContext()) using (IStoreRepository storeRepository = new StoreRepository(dbContext)) { while (true) { try { _logger.Info($"Saving"); storeRepository.Save(); } catch (DbUpdateException ex) { _logger.Error($"Failed to Save"); Console.WriteLine(ex.Message); } Console.WriteLine(); Console.WriteLine("1:\tDisplay All Names"); Console.WriteLine("2:\tSearch By Last Name"); Console.WriteLine("3:\tDisplay Order History of each location"); Console.WriteLine("4:\tQuit"); Console.WriteLine(); int input = IntValidation(1, 4); string input2; var count = 0; Customer customer; Product ProductValue; var products = storeRepository.DisplayProducts(); var products2 = products.ToList(); List <OrderDetails> orderDetails; IEnumerable <Order> OrderValue; IEnumerable <Customer> AllNames; IEnumerable <Inventories> LocationInventory; IEnumerable <ProductCat> prodCategories; IEnumerable <Product> getRecoProduct; IEnumerable <ComponentInventory> componentInventories; List <Product> Cart; List <Product> ComponentCart; decimal Total = 0; int tempOrderId; Dictionary <string, int> HashProducts; HashSet <Product> HashLoop; int inventoryId; switch (input) { case 1: AllNames = storeRepository.GetNames(); Console.WriteLine(); count = 0; _logger.Info($"Choosing Customer to Order for"); foreach (var x in AllNames) { Console.WriteLine($"\t{count}: {x.GetFullName()}"); count++; } if (count == 0) { Console.WriteLine("There are 0 Customers"); break; } var AllNamesList = AllNames.ToList(); Console.WriteLine($"Choose Customer to interact with or Press {AllNames.Count()} to go back"); input = IntValidation(0, AllNames.Count()); if (input != AllNames.Count()) { customer = AllNames.ElementAt(input); OrderValue = storeRepository.GetOrders(customer); _logger.Info($"Displaying orders for {customer.FName} {customer.LName} {customer.CustomerId}"); List <OrderDetails> temp2 = new List <OrderDetails>(); while (true) { Console.WriteLine(); Console.WriteLine("Do you want to view and sort Customer Order History?"); Console.WriteLine("1:\tYes"); Console.WriteLine("2:\tNo"); Console.WriteLine(); input = IntValidation(1, 2); if (input == 2) { break; } Console.WriteLine(); Console.WriteLine("What do you want to sort by?"); Console.WriteLine("1:\tEarliest"); Console.WriteLine("2:\tLatest"); Console.WriteLine("3:\tCheapest"); Console.WriteLine("4:\tExpensive"); Console.WriteLine(); input = IntValidation(1, 4); List <Order> orderList = OrderValue.ToList(); if (input == 1) { orderList = Order.SortList(orderList, Sort.Early); } else if (input == 2) { orderList = Order.SortList(orderList, Sort.Late); } else if (input == 3) { orderList = Order.SortList(orderList, Sort.Cheap); } else if (input == 4) { orderList = Order.SortList(orderList, Sort.Expensive); } count = 0; foreach (var x in orderList) { Console.WriteLine(); Console.WriteLine($"Order {count}:\tTime:{x.TimeStamp} \nStore: {x.Location.Name}\tCost: ${x.TotalAmount}"); orderDetails = storeRepository.GetOrderDetails(x).ToList(); temp2.AddRange(orderDetails); var y = orderDetails; foreach (var z in y) { var i = Order.GetProductName(products.ToList(), z.ProductId); Console.WriteLine($"\t{i}\tAmount:{z.Quantity} "); } count++; } } Cart = new List <Product>(); LocationInventory = storeRepository.GetInventories(customer); List <Inventories> LocationInventoryList = LocationInventory.ToList(); Total = 0; while (true) { count = 4; products = storeRepository.DisplayProducts(); Console.WriteLine(); foreach (var x in products) { if (count % 3 == 0) { Console.WriteLine($"\t{count - 4}: {x.ProductCost} {x.ProductName}\t\t "); } else { Console.Write($"\t{count - 4}: {x.ProductCost} {x.ProductName}\t\t "); } count++; } _logger.Info($"Get Recommended Items"); Product product = new Product(); List <Product> tempP = new List <Product>(); List <Order> orderList = OrderValue.ToList(); foreach (var x in orderList) { var y = storeRepository.GetOrderDetails(x).ToList(); foreach (var z in y) { foreach (var t in products) { if (t.ProductId == z.ProductId) { tempP.Add(t); } } } count++; } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Recommended Items:\n"); var getStuff = dbContext.Products.Where(x => x.ProductCategoryId == tempP[tempP.Count - 1].CategoryId).ToList(); count = 0; foreach (var x in getStuff) { if (count > 2) { break; } Console.Write($" {x.ProductName}"); count++; } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"Add Product to cart or Enter {products.Count()} to purchase it\n"); Console.WriteLine($"Purchasing from Default Location: {customer.DefaultLocation.Name}"); Console.WriteLine($"There are {Cart.Count} Items in cart for a total of ${Total}"); input = IntValidation(0, products.Count()); _logger.Info($"Choose item to add to cart"); if (input != products.Count()) { ProductValue = products.ElementAt(input); _logger.Info($"Item chosen = {ProductValue.ProductName}"); if (ProductValue.HasComponents) { componentInventories = storeRepository.GetComponents(ProductValue); ComponentCart = new List <Product>(); foreach (var x in componentInventories) { foreach (var y in products2) { if (x.ComponentProductId == y.ProductId) { ComponentCart.Add(y); } } } List <Inventories> tempInv = new List <Inventories>(); tempInv.AddRange(LocationInventoryList); Decimal tempTotal = Total; List <Product> tempCart = new List <Product>(); tempCart.AddRange(Cart); foreach (var x in ComponentCart) { if (Order.CheckCart(x, LocationInventoryList)) { Console.WriteLine($"\t{x.ProductName} has been added to cart"); Total += x.ProductCost; Cart.Add(x); } else { LocationInventoryList.Clear(); LocationInventoryList.AddRange(tempInv); Cart.Clear(); Cart.AddRange(tempCart); Total = tempTotal; Console.WriteLine(); Console.WriteLine("Inventory is out"); break; } } } else { if (Order.CheckCart(ProductValue, LocationInventoryList)) { Console.WriteLine($"\t{ProductValue.ProductName} has been added to cart"); Total += ProductValue.ProductCost; Cart.Add(ProductValue); } else { Console.WriteLine(); Console.WriteLine("Inventory is out"); } } } else { if (Cart.Count == 0) { Console.WriteLine(); Console.WriteLine("The cart is empty, so nothing was purchased!"); Console.WriteLine(); break; } else { //SA.Orders(ConsumerId,StoreId,TotalAmount) Order newOrder = new Order { CustomerId = customer.CustomerId, StoreId = customer.DefaultLocation.LocationId, TotalAmount = Total, Location = customer.DefaultLocation, Customer = customer, TimeStamp = DateTime.Now, }; storeRepository.AddOrder(newOrder, customer.DefaultLocation, customer); try { _logger.Info($"Saving"); storeRepository.Save(); } catch (DbUpdateException ex) { _logger.Error($"Failed to Save"); Console.WriteLine(ex.Message); } Thread.Sleep(50); tempOrderId = dbContext.Orders.OrderByDescending(y => y.OrderId).Select(a => a.OrderId).FirstOrDefault(); HashProducts = new Dictionary <string, int>(); HashLoop = new HashSet <Product>(); foreach (var x in Cart) { if (HashProducts.ContainsKey(x.ProductName)) { HashProducts[x.ProductName] += 1; } else { HashProducts.Add(x.ProductName, 1); } HashLoop.Add(x); } count = 0; foreach (var x in HashLoop) { count++; Console.WriteLine(count); OrderDetails newOrderDetails = new OrderDetails { OrderId = tempOrderId, ProductId = x.ProductId, Quantity = HashProducts[x.ProductName], }; storeRepository.AddOrderDetails(newOrderDetails, newOrder, x); try { _logger.Info($"Saving"); storeRepository.Save(); } catch (DbUpdateException ex) { _logger.Error($"Failed to Save"); Console.WriteLine(ex.Message); } inventoryId = dbContext.Inventory.Where(y => y.ProductId == x.ProductId && y.StoreId == customer.DefaultLocation.LocationId).Select(a => a.InventoryId).First(); Thread.Sleep(50); Inventories inventories = new Inventories { Quantity = Order.getInventory(LocationInventoryList, x.ProductId), StoreId = customer.DefaultLocation.LocationId, ProductId = x.ProductId, InventoryId = inventoryId, }; storeRepository.UpdateInventory(inventories); try { _logger.Info($"Saving"); storeRepository.Save(); } catch (DbUpdateException ex) { _logger.Error($"Failed to Save"); Console.WriteLine(ex.Message); } } } break; } } } break; case 2: _logger.Info($"Search for name name"); do { Console.WriteLine("Please enter Full/Parital Last Name to search by"); input2 = Console.ReadLine(); if (input2.Length < 200 && input2.Length > 0) { break; } else { Console.WriteLine("Please enter word with 1 - 199 characters, "); } } while (true); AllNames = storeRepository.GetNames(input2); Console.WriteLine(); count = 0; foreach (var x in AllNames) { Console.WriteLine($"\t{count}: {x.GetFullName()}"); count++; } if (count == 0) { Console.WriteLine("Your search had 0 results"); } break; case 3: _logger.Info($"Display All orders by each location"); var n = storeRepository.GetOrders().ToList(); var p = n.OrderByDescending(k => k.Location.LocationId); foreach (var a in p) { var b = dbContext.Consumer.ToList(); var z = dbContext.Store.ToList(); string name = "John Albert"; foreach (var m in z) { if (m.Consumer.Where(c => c.ConsumerId == a.CustomerId).Select(x => x.ConsumerId).FirstOrDefault() == a.CustomerId) { name = m.Consumer.Where(c => c.ConsumerId == a.CustomerId).Select(x => x.Fname).FirstOrDefault() + " " + m.Consumer.Where(c => c.ConsumerId == a.CustomerId).Select(x => x.Lname).FirstOrDefault(); } } Console.WriteLine($"{ a.Location.Name}"); Console.WriteLine($"\t{name}\t{a.TimeStamp}\t{a.TotalAmount}"); Console.WriteLine(); } break; case 4: _logger.Info($"Exiting Application"); return; } } } }
static void Main(string[] args) { Console.WriteLine("Hello! Welcome to the Revature Resturaunt!"); string inputOne = "0"; int n; bool isNumeric; int menuSwitch = 1; // Menu switch guide //1 - start menu //2 - manager menu //3 - customer menu //4 - return customer menu //5 - new customer menu //6 - customer options menu //7 - manager store view menu //8 - order menu //9 - Select store ID bool whileInMenu = true; bool whileInSecondaryMenu = true; BusinessLogic.Objects.Customer retrievedCustomer = new BusinessLogic.Objects.Customer(); BusinessLogic.Objects.Store retrievedStore = new BusinessLogic.Objects.Store(); BusinessLogic.Objects.Order inputOrder = new BusinessLogic.Objects.Order(); List <BusinessLogic.Objects.Order> orderList = new List <BusinessLogic.Objects.Order>(); StoreApp.BusinessLogic.Objects.Manager retrievedManager = new BusinessLogic.Objects.Manager(); //DB initialization DbContextOptions <StoreApplicationContext> options = new DbContextOptionsBuilder <StoreApplicationContext>() .UseSqlServer(StoreApp.DataLibrary.ConnectionData.Secret.connectionString) .Options; using var context = new StoreApplicationContext(options); DBRHandler = new RetrieveDatabaseHandler(context); while (whileInMenu) { string managerIDInput; int managerID; int customerID; int storeNum; switch (menuSwitch) { case 1: //Start menu while (whileInSecondaryMenu) { Console.WriteLine("Are you using this console as a manager or a customer?\n[1] Manager\n[2] Customer\n"); inputOne = CheckAndReturnCustomerOptionChosen(Console.ReadLine(), 2); if (inputOne == "1") //Manager { //code for manager //Can display current stocks and things for locations and other things stored //Managment can stock their stores and check and edit customer data whileInSecondaryMenu = false; menuSwitch = 2; } else if (inputOne == "2") //Customer { //code for customer //Will run code to make new customer, retrieve old customer data, and place orders menuSwitch = 3; whileInSecondaryMenu = false; } else //Invalid input { Console.WriteLine("Invalid input, please type one of the following options"); } } whileInSecondaryMenu = true; //resets menu true to go into next menu break; case 2: // manager menu //Some code to compare manager ID to the table and welcome manager options while (whileInSecondaryMenu) { Console.WriteLine("What is your manager ID?"); managerIDInput = Console.ReadLine(); isNumeric = int.TryParse(managerIDInput, out n); if (isNumeric == false) { Console.WriteLine("Invalid characters. Please try again with a numerical value"); break; } else //if the input only has numbers in it { managerID = Int32.Parse(managerIDInput); try { retrievedManager = DBRHandler.GetManagerDataFromID(managerID); retrievedStore = DBRHandler.GetStoreFromStoreNumber(retrievedManager.storeNumberManaged); Console.WriteLine("Welcome back, " + retrievedManager.firstName + " " + retrievedManager.lastName + "!\nManager of Store Number: " + retrievedManager.storeNumberManaged + "\n"); menuSwitch = 7; whileInSecondaryMenu = false; //set case to go to the manager options menu on 7 } catch (NullReferenceException e) { Console.WriteLine("Unable to perform the operation due to null value returned with Customer ID " + managerID + ": " + e.Message + "\n"); } catch (Exception e) { Console.WriteLine("Unknown exeption " + e); } } } whileInSecondaryMenu = true; //resets menu true to go into next menu break; case 3: //general customer menu while (whileInSecondaryMenu) { Console.WriteLine("Are you a new customer or a return customer?\n[1] New Customer\n[2] Return Customer\n"); inputOne = CheckAndReturnCustomerOptionChosen(Console.ReadLine(), 2); if (inputOne == "1") { whileInSecondaryMenu = false; menuSwitch = 5; } else if (inputOne == "2") { whileInSecondaryMenu = false; menuSwitch = 4; } else { Console.WriteLine("Invalid input, please type one of the following options"); } } whileInSecondaryMenu = true; break; case 4: //return customer while (whileInSecondaryMenu) { Console.WriteLine("Welcome back! What is your customer ID?"); inputOne = Console.ReadLine(); isNumeric = int.TryParse(inputOne, out n); if (isNumeric == false) { Console.WriteLine("Invalid characters. Please try again with a numerical value"); break; } else //if the input only has numbers in it { customerID = Int32.Parse(inputOne); try { retrievedCustomer = DBRHandler.GetCustomerDataFromID(customerID); Console.WriteLine("Welcome back, " + retrievedCustomer.firstName + " " + retrievedCustomer.lastName + "! What can we do for you today?"); menuSwitch = 6; whileInSecondaryMenu = false; } catch (NullReferenceException e) { Console.WriteLine("Unable to perform the operation due to null value returned with Customer ID " + customerID + ": " + e.Message + "\n"); } catch (Exception e) { Console.WriteLine("Unknown exeption " + e); } } } whileInSecondaryMenu = true; //resets menu true to go into next menu break; case 5: //new customer menu StoreApp.BusinessLogic.Objects.Customer newCust = new StoreApp.BusinessLogic.Objects.Customer(); while (whileInSecondaryMenu) { if (newCust.CheckCustomerNotNull() == false) { if (newCust.firstName == null) { Console.WriteLine("What is your first name?"); newCust.firstName = Console.ReadLine(); } else if (newCust.lastName == null) { Console.WriteLine("What is your last name?"); newCust.lastName = Console.ReadLine(); } else if (newCust.customerAddress.CheckAddressNotNull() == false) { Console.WriteLine("Please enter an address. What is your street?"); newCust.customerAddress.street = Console.ReadLine(); Console.WriteLine("Please enter a city"); newCust.customerAddress.city = Console.ReadLine(); Console.WriteLine("Please enter a state"); newCust.customerAddress.state = Console.ReadLine(); Console.WriteLine("Please enter a zip"); newCust.customerAddress.zip = Console.ReadLine(); } } else { try { Console.WriteLine("Adding profile to database. . .\n"); DBIHandler.AddNewCustomerData(newCust, context); Console.WriteLine("Customer profile successfully created! Welcome, " + newCust.firstName + "!\n"); int newID = DBRHandler.GetNewCustomerID(); //Note, not safe for multiple connections to the DB inputting at once. Console.WriteLine("Your new customer ID is: " + newID); retrievedCustomer = DBRHandler.GetCustomerDataFromID(newID); whileInSecondaryMenu = false; menuSwitch = 6; } catch (Exception e) { Console.WriteLine("Unknown exception thrown: " + e); } } } whileInSecondaryMenu = true; //resets menu true to go into next menu break; case 6: //customer options menu while (whileInSecondaryMenu) { Console.WriteLine("Customer Options\n[1] Place order\n[2] View profile information\n[3] View order history\n[4] Exit to start menu"); inputOne = CheckAndReturnCustomerOptionChosen(Console.ReadLine(), 4); if (inputOne == "1") { whileInSecondaryMenu = false; menuSwitch = 9; } else if (inputOne == "2") { Console.WriteLine("\n------------------------------------------"); Console.WriteLine("Name: " + retrievedCustomer.firstName + " " + retrievedCustomer.lastName); Console.WriteLine("ID: " + retrievedCustomer.customerID); Console.WriteLine("\nAddress: \n" + retrievedCustomer.customerAddress.street + "\n" + retrievedCustomer.customerAddress.city + "\n" + retrievedCustomer.customerAddress.state + "\n" + retrievedCustomer.customerAddress.zip); Console.WriteLine("------------------------------------------\n"); } else if (inputOne == "3") { orderList = DBRHandler.GetListOfOrdersByCustomerID(retrievedCustomer.customerID); foreach (BusinessLogic.Objects.Order BLOrder in orderList) { BLOrder.customerProductList = DBRHandler.GetListOrderProductByOrderID(BLOrder); BLOrder.storeLocation = DBRHandler.GetStoreInformationFromOrderNumber(BLOrder.orderID); } if (orderList == null || orderList.Count == 0) { Console.WriteLine("No orders to display under " + retrievedCustomer.firstName + " " + retrievedCustomer.lastName); } else { foreach (BusinessLogic.Objects.Order order in orderList) { Console.WriteLine("-------------------------------"); Console.WriteLine("Store Number: " + order.storeLocation.storeNumber); Console.WriteLine("Order Number: " + order.orderID); foreach (BusinessLogic.Objects.Product product in order.customerProductList) { Console.WriteLine(product.name + ": " + product.amount); } } Console.WriteLine("-------------------------------\n"); } } else if (inputOne == "4") { whileInSecondaryMenu = false; retrievedCustomer = new BusinessLogic.Objects.Customer(); //resets the customer data that was retrieved by this point in the menu menuSwitch = 1; } else { Console.WriteLine("Invalid input, please type one of the following options"); } } whileInSecondaryMenu = true; //resets menu true to go into next menu break; case 7: //manager store view menu while (whileInSecondaryMenu) { Console.WriteLine("Options\n[1] View Store Information\n[2] View Store Inventory\n[3] View all customer order history\n[4] Exit to start menu"); inputOne = CheckAndReturnCustomerOptionChosen(Console.ReadLine(), 4); if (inputOne == "1") //View store info { Console.WriteLine("------------ Information for Store Number " + retrievedStore.storeNumber + " ------------"); Console.WriteLine("Address: \nStreet: " + retrievedStore.address.street + "\nCity: " + retrievedStore.address.city + "\nState: " + retrievedStore.address.state + "\nZip: " + retrievedStore.address.zip + "\n"); } else if (inputOne == "2") //View store inventory { retrievedStore.storeInventory = DBRHandler.GetStoreInventoryByStoreNumber(retrievedStore.storeNumber); Console.WriteLine("------------ Store inventory ------------"); foreach (BusinessLogic.Objects.Product BLProd in retrievedStore.storeInventory.productData) { Console.WriteLine(BLProd.name + ": " + BLProd.amount); } Console.WriteLine("\n"); } else if (inputOne == "3") { orderList = new List <BusinessLogic.Objects.Order>(); orderList = DBRHandler.GetListOfOrdersFromStoreNumber(retrievedStore.storeNumber); foreach (BusinessLogic.Objects.Order BLOrder in orderList) { BLOrder.customerProductList = DBRHandler.GetListOrderProductByOrderID(BLOrder); BLOrder.storeLocation = DBRHandler.GetStoreInformationFromOrderNumber(BLOrder.orderID); } if (orderList == null || orderList.Count == 0) { Console.WriteLine("No orders to display under " + retrievedCustomer.firstName + " " + retrievedCustomer.lastName); } else { foreach (BusinessLogic.Objects.Order order in orderList) { if (order.storeLocation.storeNumber == retrievedStore.storeNumber) { Console.WriteLine("-------------------------------"); Console.WriteLine("Store Number: " + order.storeLocation.storeNumber); Console.WriteLine("Order Number: " + order.orderID); Console.WriteLine("Customer ID: " + order.customer.customerID); foreach (BusinessLogic.Objects.Product product in order.customerProductList) { Console.WriteLine(product.name + ": " + product.amount); } } } Console.WriteLine("-------------------------------\n"); } } else if (inputOne == "4") { retrievedManager = new BusinessLogic.Objects.Manager(); retrievedStore = new BusinessLogic.Objects.Store(); menuSwitch = 1; whileInSecondaryMenu = false; } } whileInSecondaryMenu = true; break; case 8: //Order menu bool decided = false; string temp; while (whileInSecondaryMenu) { while (decided == false) { try { inputOrder = new BusinessLogic.Objects.Order(); BusinessLogic.Objects.Product inputProd = new BusinessLogic.Objects.Product(); retrievedStore.storeInventory = DBRHandler.GetStoreInventoryByStoreNumber(retrievedStore.storeNumber); foreach (BusinessLogic.Objects.Product prod in retrievedStore.storeInventory.productData) { inputProd = prod; inputProd.amount = 0; Console.WriteLine("How many " + prod.name + " would you like to order?\n"); temp = Console.ReadLine(); inputProd.amount = Int32.Parse(temp); inputOrder.customerProductList.Add(inputProd); } Console.WriteLine("---------------------------"); Console.WriteLine("Your order consists of: \n"); foreach (BusinessLogic.Objects.Product prod in inputOrder.customerProductList) { Console.WriteLine(prod.name + ": " + prod.amount + "\n"); } Console.WriteLine("Is this alright?" + "\n[1] Yes\n[2] No"); inputOne = CheckAndReturnCustomerOptionChosen(Console.ReadLine(), 2); if (inputOne == "1") { decided = true; Console.WriteLine("Please wait while your order is created. . .\n"); //uses input handler to input order into DB inputOrder.customer = retrievedCustomer; inputOrder.storeLocation = retrievedStore; bool goodOrder = inputOrder.CheckOrderIsValid(); //goodOrder = retrievedStore.storeInventory.CheckOrderAgainstInventory(inputOrder.customerProductList); if (goodOrder == true) { try { InputWholeOrderAndUpdateInventory(inputOrder, retrievedStore, context); menuSwitch = 6; whileInSecondaryMenu = false; Console.WriteLine("Order successfully created! Thank you for your business!\nReturning back to customer menu. . . \n"); } catch (Exception e) { Console.WriteLine("Unable to perform the operation: \n" + e.Message); } } else { Console.WriteLine("Order was invalid! Please try again with acceptable values!"); inputOrder = new Order(); decided = false; } } else if (inputOne == "2") { Console.WriteLine("Please type in your order once more with the desired values."); } else { Console.WriteLine("Invalid input, please type one of the following options."); } } catch (Exception e) { Console.WriteLine(e.Message + "\nPlease enter correct numerical values for your order."); } } } whileInSecondaryMenu = true; break; case 9: //Select order store menu while (whileInSecondaryMenu) { Console.WriteLine("What store number are you ordering from?"); inputOne = Console.ReadLine(); isNumeric = int.TryParse(inputOne, out n); if (isNumeric == false) { Console.WriteLine("Invalid characters. Please try again with a numerical value"); break; } else //if the input only has numbers in it { storeNum = Int32.Parse(inputOne); try { retrievedStore = DBRHandler.GetStoreFromStoreNumber(storeNum); menuSwitch = 8; whileInSecondaryMenu = false; } catch (Exception e) { Console.WriteLine("Error finding store with input ID: " + e.Message + "\n"); } } } whileInSecondaryMenu = true; break; default: Console.WriteLine("Default case"); break; } } }