public void AddToShoppingList(List <string> FoodItemsToChange, List <float> AmountsToChange, List <string> Units, FoodManager foodManager, ProgramManager programManager) { if (FoodItemsToChange != null) { for (int i = 0; i < FoodItemsToChange.Count; i++) { float AmountToRemove = UnitConverter.GetAmountToRemove(FoodItemsToChange[i], AmountsToChange[i], Units[i], foodManager); if (USUsersFoods.ContainsKey(FoodItemsToChange[i])) { foreach (KeyValuePair <string, FoodDef> element in USUsersFoods) { if (element.Value.USName == FoodItemsToChange[i] && element.Value.Amount - AmountToRemove < 0) { if (!programManager.UserShoppingList.USFoodsToBuy.Contains(FoodItemsToChange[i])) { programManager.UserShoppingList.AddToShoppingList(element.Value.USName, element.Value.BGName); } } } } else { if (!programManager.UserShoppingList.USFoodsToBuy.Contains(FoodItemsToChange[i])) { programManager.UserShoppingList.AddToShoppingList(FoodItemsToChange[i], foodManager.Foods[FoodItemsToChange[i]].BGName); } } } programManager.SaveShoppingList(); } // Only if requirements are met does the function return true. }
/// <summary> /// After using a certian product changes the Amount left, or if the AmountToChange is 0 removes the Item /// </summary> /// <param name="FoodItemToChange"></param> /// <param name="AmountToChange"></param> public void ModifyFoodItemAmount(List <string> FoodItemsToChange, List <float> AmountsToChange, List <string> Units, FoodManager foodManager, ProgramManager programManager) { for (int i = 0; i < FoodItemsToChange.Count; i++) { float AmountToRemove = UnitConverter.GetAmountToRemove(FoodItemsToChange[i], AmountsToChange[i], Units[i], foodManager); foreach (KeyValuePair <string, FoodDef> element in USUsersFoods) { if (element.Value.USName.ToLower() == FoodItemsToChange[i].ToLower() && element.Value.Amount - AmountToRemove >= 0) { element.Value.Amount -= AmountToRemove; } } } for (int i = 0; i < USUsersFoods.Count; i++) { if (USUsersFoods.ElementAt(i).Value.Amount == 0) { if (!programManager.UserShoppingList.USFoodsToBuy.Contains(FoodItemsToChange[i])) { programManager.UserShoppingList.AddToShoppingList(USUsersFoods.ElementAt(i).Value.USName, USUsersFoods.ElementAt(i).Value.BGName); } USUsersFoods.Remove(USUsersFoods.ElementAt(i).Key); } } SaveFridge(); programManager.SaveShoppingList(); }