public void CreateUpdateVendingMachineInventory() { using (StreamReader sr = new StreamReader(INVENTORY_LIST_PATH)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] productArray = line.Split("|"); string type = productArray[3]; decimal price = decimal.Parse(productArray[2]); string name = productArray[1]; string slot = productArray[0]; endOfDaySalesReport[name] = 0; switch (type) { case "Chip": ProductList[slot] = new ProductInventory(slot, name, price, "Crunch Crunch, Yum!"); break; case "Gum": ProductList[slot] = new ProductInventory(slot, name, price, "Chew Chew, Yum!"); break; case "Drink": ProductList[slot] = new ProductInventory(slot, name, price, "Glug Glug, Yum!"); break; case "Candy": ProductList[slot] = new ProductInventory(slot, name, price, "Munch Munch, Yum!"); break; default: break; } } } }
public string PurchaseProduct(string input) { ProductInventory product = ProductList[input]; if (product.Price > Balance) { return("\nInsufficient Funds; Please Deposit Additional Funds"); } else if (product.AmountOfProduct == 0) { return("SOLD OUT"); } else { Balance -= product.Price; product.AmountOfProduct--; endOfDaySalesReport[product.Name]++; TotalSales += product.Price; WriteToAuditLog($"{DateTime.Now} {product.Name} {product.Slot} {product.Price,0:C} {Balance,0:C}"); return(product.OutPutMessage); } }