예제 #1
0
        private static void Main(string[] args)
        {
            var weatherData = new WeatherData();
            var simple      = new SimpleDisplay();
            var full        = new FullDisplay();

            // Register some observers
            weatherData.RegisterObserver(simple);
            weatherData.RegisterObserver(full);

            // Change the weather and get notified
            weatherData.SetMeasurements(25, 65.5f, 30.4f);

            // Deregister one observer
            weatherData.DeregisterObserver(simple);

            // Change the weather and notify the remaining observer
            weatherData.SetMeasurements(-1, 1f, 2f);

            // Deregister the last observer and change the weather
            weatherData.DeregisterObserver(full);
            weatherData.SetMeasurements(100, 100f, 100f);

            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var weatherData   = new WeatherData();
            var simpleDisplay = new SimpleDisplay();
            var fullDisplay   = new FullDisplay(weatherData);

            weatherData.SetMeasurements(25, 65.5f, 30.4f);

            Console.ReadKey();
        }
예제 #3
0
        public void DisplayOneOrderPrintOnConsole()
        {
            IDisplay        dis    = new SimpleDisplay();
            List <CProduct> supply = new List <CProduct>
            {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 4),
                new CProduct("222", "orange", "Produce", 0.88, 4)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");
            COrder    order    = new COrder(store, customer, DateTime.Today, 100, p);

            dis.DisplayOneOrder(order);
            Assert.True(true);
        }
예제 #4
0
        public void SimplyWriteData()
        {
            List <CProduct> supply = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 4),
                new CProduct("222", "orange", "Produce", 0.88, 4)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");
            // orders the same as the store's inventory
            COrder        order = new COrder(store, customer, DateTime.Today, 100, p);
            SimpleDisplay dis   = new SimpleDisplay();

            string          path    = "../../../SimplyWriteData.json";
            JsonFilePersist persist = new JsonFilePersist(path);

            customer.PlaceOrder(store, order);
            persist.WriteStoreData(store);
        }
예제 #5
0
        static void Main(string[] args)
        {
            using var logStream = new StreamWriter("ef-logs.txt");
            var optionsBuilder = new DbContextOptionsBuilder <Project0databaseContext>();

            optionsBuilder.UseSqlServer(GetConnectionString());
            optionsBuilder.LogTo(logStream.WriteLine, LogLevel.Debug);
            s_dbContextOptions = optionsBuilder.Options;

            StoreRepository repo = new StoreRepository(s_dbContextOptions);
            IDisplay        sd   = new SimpleDisplay();
            ISearch         ss   = new SimpleSearch();

            // new mvc version
            // display all store locations to choose from
            Console.WriteLine("Welcome to XYZ Enterprise, below are a list of our locations:\n ");

            List <CStore> storeBasics = repo.GetAllStores();

            sd.DisplayAllStores(storeBasics);

            Console.WriteLine("Select a store location first:");
            string storeLoc = Console.ReadLine();
            CStore store    = null;

            while (store == null)
            {
                store = repo.GetAStore(storeLoc);
                if (NullChecker(store))
                {
                    storeLoc = Console.ReadLine();
                    continue;
                }
                else
                {
                    break;
                }
            }
            // set up inventory, not the same as add products, more like reset inventory
            InventorySetup(repo, storeLoc, store);
            while (true)
            {
                // read from databse
                // string path = "../../../SimplyWriteData.json";
                // JsonFilePersist persist = new JsonFilePersist(path);
                // CStore store = persist.ReadStoreData();

                Console.WriteLine("\nChoose one of the following operations:\n  1.Add a new customer\n  2.Process an order\n  3.Search a customer\n  4.Display an order\n  5.Display orders of a customer\n  6.Display orders of a store\n  7.Exit the console\n");
                // validation

                bool   hasProfileSetup = false;
                string choice          = Console.ReadLine();
                if (choice == "1")
                {
                    // avoid repetition if already has all customer profiles
                    if (!hasProfileSetup)
                    {
                        CustomerSetup(repo, storeLoc, store);
                        hasProfileSetup = true;
                    }
                    // add a new customer profile if not exist, or nothing
                    CheckAndAddOneCustomer(repo, storeLoc, store, ss);
                }
                else if (choice == "2")
                {
                    // same process as choiece 2 in the beginning
                    if (!hasProfileSetup)
                    {
                        CustomerSetup(repo, storeLoc, store);
                        hasProfileSetup = true;
                    }
                    string customerid = CheckAndAddOneCustomer(repo, storeLoc, store, ss);

                    // process begins
                    List <CProduct> products     = ProductsSetup(repo);
                    string          orderid      = OIDGen.Gen();
                    string          extraStuff   = "this is outdated";
                    string          myStuff      = "my change must be reainted";
                    double          totalCost    = store.CalculateTotalPrice(products);
                    bool            isSuccessful = false;
                    COrder          newOrder     = new COrder(orderid, store, store.CustomerDict[customerid],
                                                              DateTime.Now, totalCost);
                    try
                    {
                        // quantity limits
                        newOrder.ProductList = products;
                        isSuccessful         = true;
                        Console.WriteLine("Order created successfully!");
                    }
                    catch (ArgumentException e)
                    {
                        isSuccessful = false;
                        Console.WriteLine("This order exceeds the max allowed quantities, failed to create the order!");
                    }

                    if (isSuccessful)
                    {
                        if (!store.CheckInventory(newOrder))
                        {
                            Console.WriteLine("Do not have enough products left to fulfill this order!");
                        }
                        else
                        {
                            // map products to an order, orders to a customer,
                            // store now has complete information
                            foreach (var pair in store.CustomerDict)
                            {
                                CCustomer customer = pair.Value;
                                customer.OrderHistory = repo.GetAllOrdersOfOneCustomer(customer.Customerid, store, customer);
                                foreach (var order in customer.OrderHistory)
                                {
                                    order.ProductList = repo.GetAllProductsOfOneOrder(order.Orderid);
                                    order.TotalCost   = store.CalculateTotalPrice(order.ProductList);
                                }
                            }
                            store.UpdateInventoryAndCustomerOrder(newOrder);
                            repo.CustomerPlaceOneOrder(newOrder, store, totalCost);
                        }
                    }
                }

                else if (choice == "3")
                {
                    while (true)
                    {
                        Console.WriteLine("Enter Customer's first name");
                        string firstname = ValidateNotNull(Console.ReadLine());
                        Console.WriteLine("Enter Customer's last name");
                        string lastname = ValidateNotNull(Console.ReadLine());
                        Console.WriteLine("Enter Customer's phone number");
                        string phonenumber = ValidatePhonenumber(Console.ReadLine());

                        CCustomer foundCustomer = repo.GetOneCustomerByNameAndPhone(firstname, lastname, phonenumber);
                        if (NullChecker(foundCustomer))
                        {
                            continue;
                        }
                        else
                        {
                            Console.WriteLine($"{foundCustomer.Customerid} found, customer alreay exist in the database");
                            break;
                        }
                    }
                }
                else if (choice == "4")
                {
                    while (true)
                    {
                        Console.WriteLine("What is the orderid?");
                        string orderid    = ValidateNotNull(Console.ReadLine());
                        COrder foundOrder = repo.GetAnOrderByID(orderid);
                        if (NullChecker(foundOrder))
                        {
                            continue;
                        }
                        else
                        {
                            sd.DisplayOneOrder(foundOrder);
                            break;
                        }
                        // need an option to search by store location, customerid, and orderdata
                    }
                }
                else if (choice == "5")
                {
                    while (true)
                    {
                        // same as search for a customer in the beginning
                        Console.WriteLine("Enter Customer's first name");
                        string firstname = ValidateNotNull(Console.ReadLine());
                        Console.WriteLine("Enter Customer's last name");
                        string lastname = ValidateNotNull(Console.ReadLine());
                        Console.WriteLine("Enter Customer's phone number");
                        string    phonenumber   = ValidatePhonenumber(Console.ReadLine());
                        CCustomer foundCustomer = repo.GetOneCustomerOrderHistory(firstname, lastname, phonenumber, store);

                        if (NullChecker(foundCustomer))
                        {
                            continue;
                        }
                        else
                        {
                            sd.DisplayAllOrders(foundCustomer.OrderHistory);
                            break;
                        }
                    }
                }
                else if (choice == "6")
                {
                    while (true)
                    {
                        Console.WriteLine("What is the store location you seek?");
                        string seekLoc   = ValidateNotNull(Console.ReadLine());
                        CStore seekStore = repo.GetOneStoreOrderHistory(seekLoc);
                        if (NullChecker(seekStore))
                        {
                            continue;
                        }
                        foreach (var pair in seekStore.CustomerDict)
                        {
                            sd.DisplayAllOrders(pair.Value.OrderHistory);
                        }
                        break;

                        /*
                         * CStore seekStore = repo.GetAStore(seekLoc);
                         * if (NullChecker(seekStore)) continue;
                         *
                         * seekStore.CustomerDict = repo.GetAllCustomersAtOneStore(seekLoc);
                         *
                         * foreach (var pair in seekStore.CustomerDict)
                         * {
                         *  CCustomer cust = pair.Value;
                         *  cust.OrderHistory = repo.GetAllOrdersOfOneCustomer(cust.Customerid, seekStore, cust);
                         *  foreach (var order in cust.OrderHistory)
                         *  {
                         *      order.ProductList = repo.GetAllProductsOfOneOrder(order.Orderid);
                         *      order.TotalCost = store.CalculateTotalPrice(order.ProductList);
                         *  }
                         *  sd.DisplayAllOrders(cust.OrderHistory);
                         * }
                         * break;
                         */
                    }
                }
                else if (choice == "7")
                {
                    Console.WriteLine("Thank you for using XYZ Enterprise!");
                    break;
                }
                // invalid commands
                else
                {
                    Console.WriteLine("Choose one of the options above, other inputs are invalid!");
                }
            }
        }