コード例 #1
0
        public static void ProcessOrder()
        {
            List <StockRequests> requests = LoadStockRequest();

            Console.WriteLine("\nEnter Request to process (press Q to go back)");
            string inputOrderToProcess = Console.ReadLine();

            // exit back to owner menu
            if (inputOrderToProcess == "q")
            {
                RunOwner();
            }

            // check to see if user input is in range of requests index
            int  index     = 0;
            bool isNumeric = int.TryParse(inputOrderToProcess, out index);

            if (isNumeric == true && index <= requests.Count)
            {
                index = Convert.ToInt32(inputOrderToProcess) - 1;
            }
            else
            {
                Console.WriteLine("Invaild option");
                ProcessOrder();
            }

            StockRequests processObject = requests[index];

            store = JsonConvert.DeserializeObject <List <Franchisee> >(File.ReadAllText(processObject.Store + "_inventory.json"));
            bool triggered = false;

            for (int x = 0; x <= store.Count - 1; x = x + 1)
            {
                if (store[x].Name == processObject.Name && processObject.Available == true)
                {
                    triggered = true;
                    string storeName = processObject.Store;
                    store[x].StockLevel += requests[index].Quantity;
                    removeStockOwner(processObject);
                    requests.RemoveAt(index);
                    File.WriteAllText("stockrequests.json", JsonConvert.SerializeObject(requests, Formatting.Indented));
                    File.WriteAllText(storeName + "_inventory.json", JsonConvert.SerializeObject(store, Formatting.Indented));
                    reindexStockRequests(requests);
                }
                else if (processObject.Available == false)
                {
                    Console.WriteLine("Not enough stock to process order");
                    ProcessOrder();
                }
            }

            if (triggered == false)
            {
                Console.WriteLine("Invaild option");
                ProcessOrder();
            }
        }
コード例 #2
0
        public static void removeStockOwner(StockRequests request)
        {
            List <Owner> owner = LoadOwnerStock();

            for (int x = 0; x <= owner.Count - 1; x = x + 1)
            {
                if (owner[x].Name == request.Name)
                {
                    owner[x].StockLevel -= request.Quantity;
                    File.WriteAllText("owners_inventory.json", JsonConvert.SerializeObject(owner, Formatting.Indented));
                }
            }
        }