private void PlaceOrderToStoreLocation()
        {
            var data = CreateOrderData();

            _ = StoreManagerApplication.Create <Order>(data);
            Console.WriteLine($"Order placed successfully.");
        }
        private void AddCustomer()
        {
            var data = CreateCustomerData();

            _ = StoreManagerApplication.Create <Customer>(data);
            Console.WriteLine($"Customer with name: '{data.LastName}, {data.FirstName}' created successfully.");
        }
        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));
        }
 public void CreateTestCustomer(string firstName, string lastName, string email, string phoneNumber, int addressId, int year, int month, int day, int?defaultStoreLocation)
 {
     try {
         CustomerData data = new CustomerData(firstName, lastName, email, phoneNumber, addressId, new DateTime(year, month, day), defaultStoreLocation);
         StoreManagerApplication.Create <Customer>(data);
     } catch (Exception) {
         Assert.True(false);
     }
 }
        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));
        }
        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));
        }
        protected OperatingLocationData CreateOperatingLocationData()
        {
            // Get the store that owns this location
            int storeId = PromptForCreateOrExist <Store>(
                () => {
                var data = CreateStoreData();
                return(StoreManagerApplication.Create <Store>(data));
            },
                () => PromptForId <Store>()
                );

            // Get the address of this location
            int addressId = PromptForCreateOrExist <Address>(
                () => {
                var data = CreateAddressData();
                return(StoreManagerApplication.Create <Address>(data));
            },
                () => PromptForId <Address>()
                );

            return(new OperatingLocationData(storeId, addressId));
        }