protected OrderData CreateOrderData() { int customerId = -1; int operatingLocationId = -1; Dictionary <int, int> productsRequested = new Dictionary <int, int>(); // Get the customer id customerId = PromptForCreateOrExist <Customer>( () => { // Create a new customer var data = CreateCustomerData(); return(StoreManagerApplication.Create <Customer>(data)); }, // Get the customer id () => PromptForId <Customer>() ); // Get the store that owns the location int storeId = PromptForCreateOrExist <Store>( () => { var data = CreateStoreData(); return(StoreManagerApplication.Create <Store>(data)); }, () => PromptForId <Store>() ); var store = StoreManagerApplication.GetData <Store>(storeId) as StoreData; // Prompt for a store, then look through the locations it has var options = store.OperatingLocationIds.Select(id => { var data = StoreManagerApplication.GetData <OperatingLocation>(id) as OperatingLocationData; var address = StoreManagerApplication.GetData <Address>(data.AddressId) as AddressData; return($"{store.Name} - {address}"); }).ToArray(); // Show the available locations that can be chosen from int selectedOption = CUI.PromptForMenuSelection(options, false); operatingLocationId = store.OperatingLocationIds[selectedOption]; // Get the products the user wants UntilItIsDone(() => { // Add products and the inventory they have int productId = PromptForCreateOrExist <Product>( () => { var data = CreateProductData(); return(StoreManagerApplication.Create <Product>(data)); }, () => PromptForId <Product>() ); int threshold = store.Inventory[productId].Item2 ?? store.Inventory[productId].Item1; // Get the count int count = CUI.PromptRange("Enter the count of said product", 0, threshold); productsRequested[productId] = count; return(!CUI.PromptForBool("Add another product?", "yes", "no")); }); return(new OrderData(customerId, operatingLocationId, productsRequested)); }
protected int PromptForCreateOrExist <T>(Func <int> creationFunction, Func <int> existingFunction) where T : SEntity { int result; bool itemExists = StoreManagerApplication.Any <T>(); bool createItem = true; if (itemExists) { createItem = CUI.PromptForBool($"Create a new {_typeNames[typeof(T)]} or use one that is existing?", "create", "existing"); } else { Console.WriteLine($"No {_typeNames[typeof(T)]}s exist; please create a {_typeNames[typeof(T)]}."); } if (createItem) { // create the item result = creationFunction(); } else { // just get the id result = existingFunction(); } return(result); }
protected ProductData CreateProductData() { string name = CUI.PromptForInput("Enter the product name", false); decimal price = CUI.PromptRange("Enter the product price", 0.01M, decimal.MaxValue); decimal?discount = CUI.PromptForBool("Place a discount on this product?", "yes", "no") ? CUI.PromptRange("Enter the discount percentage", 0, 100) : null; return(new ProductData(name, price, discount)); }
protected int PromptForId <T>() where T : SEntity { int id = -1; UntilItIsDone(() => { id = CUI.PromptRange($"Please enter the ID for the {_typeNames[typeof(T)]}", 0, StoreManagerApplication.MaxId <T>()); return(StoreManagerApplication.IdExists <T>(id)); }); return(id); }
protected AddressData CreateAddressData() { string addressLine1 = CUI.PromptForInput("Enter address line 1", false); string addressLine2 = CUI.PromptForInput("Enter address line 2", true); string city = CUI.PromptForInput("Enter the city", false); string state = CUI.PromptForInput("Enter the state", true); state = string.IsNullOrWhiteSpace(state) ? null : state; string country = CUI.PromptForInput("Enter the country", false); string zipCode = CUI.PromptForInput("Enter the Zip Code", false); return(new AddressData(addressLine1, addressLine2, city, state, country, zipCode)); }
protected StoreData CreateStoreData() { string storeName = CUI.PromptForInput("Enter the store name", false); List <int> operatingLocationIds = new List <int>(); List <int> customerIds = new List <int>(); Dictionary <int, Tuple <int, int?> > inventory = new Dictionary <int, Tuple <int, int?> >(); int locationId; UntilItIsDone(() => { // Add operating locations locationId = PromptForCreateOrExist <OperatingLocation>( () => { // Create a new operating location var data = CreateOperatingLocationData(); return(StoreManagerApplication.Create <OperatingLocation>(data)); }, // Prompt for an operating location () => PromptForId <OperatingLocation>() ); operatingLocationIds.Add(locationId); return(!CUI.PromptForBool("Add another operating location?", "yes", "no")); }); UntilItIsDone(() => { // Add products and the inventory they have int productId = PromptForCreateOrExist <Product>( () => { var data = CreateProductData(); return(StoreManagerApplication.Create <Product>(data)); }, () => PromptForId <Product>() ); // Get the count int count = CUI.PromptRange("Enter the count of said product", 0, int.MaxValue); int?threshold = CUI.PromptForBool("Set a product threshold?", "yes", "no") ? CUI.PromptRange("Enter the product threshold", 1, count) : null; inventory[productId] = new Tuple <int, int?>(count, threshold); return(!CUI.PromptForBool("Add another product?", "yes", "no")); }); return(new StoreData(storeName, operatingLocationIds, inventory)); }
private void SearchCustomersByName() { // get the name they wish to search for string userInput = CUI.PromptForInput("Enter the name in the format of 'first, last'", false); // get a list of the results var customerIds = StoreManagerApplication.GetCustomerIdsByName(userInput); if (customerIds.Any()) { // display the results customerIds.ForEach(cid => DisplayCustomer(cid, true)); } else { Console.WriteLine($"No customers found with name like '{userInput}'."); } }
public override void Run() { int selectedOption; // Set up the console options here UntilItIsDone(() => { selectedOption = CUI.PromptForMenuSelection(_actions.Keys.ToArray(), true); if (selectedOption == -1) { return(true); } var action = _actions.Values.ElementAt(selectedOption); action(); Console.WriteLine(); return(selectedOption == -1); }); }
protected CustomerData CreateCustomerData() { string firstName = CUI.PromptForInput("Enter their first name", false); string lastName = CUI.PromptForInput("Enter their last name", false); string email = CUI.PromptForEmail("Enter their email"); string phoneNumber = CUI.PromptForPhoneNumber("Enter their phone number"); int addressId = PromptForCreateOrExist <Address>( () => { var temp = CreateAddressData(); return(StoreManagerApplication.Create <Address>(temp)); }, () => PromptForId <Address>() ); DateTime birthDate = CUI.PromptForDateTime("Enter a birth date", CUI.TimeFrame.Past, true); int? defaultStoreLocationId = CUI.PromptForBool("Set a default store location?", "yes", "no") ? PromptForId <OperatingLocation>() : null; return(new CustomerData(firstName, lastName, email, phoneNumber, addressId, birthDate, defaultStoreLocationId)); }
private void DisplayStoreOrderHistory() { // Get all of the stores var stores = StoreManagerApplication.GetAllData <Store>() .Select(data => data as StoreData); // Get their names var storeNames = stores.Select(sd => sd.Name).ToArray(); // See which one the user wishes to see int selectedOption = CUI.PromptForMenuSelection(storeNames, false); // Get the store they wish to see var selectedStore = stores.ElementAt(selectedOption); if (selectedStore.OrderIds.Any()) { // display all of the orders selectedStore.OrderIds.ForEach(o => DisplayOrder(o)); } else { Console.WriteLine($"No orders for '{selectedStore.Name}'"); } }