private IngredientSet GetIngredientSet(int id, out bool cachedAdd,
                                        out bool cachedChange, out bool cachedRemove)
 {
     cachedAdd    = false;
     cachedChange = false;
     cachedRemove = false;
     foreach (IngredientSet ingredientSet in _ingredientSetsAdded)
     {
         if (ingredientSet.Id == id)
         {
             cachedAdd = true;
             return(ingredientSet);
         }
     }
     foreach (IngredientSet ingredientSet in _ingredientSetsNeedingUpdate)
     {
         if (ingredientSet.Id == id)
         {
             cachedChange = true;
             return(ingredientSet);
         }
     }
     foreach (IngredientSet ingredientSet in _ingredientSetsRemoved)
     {
         if (ingredientSet.Id == id)
         {
             cachedRemove = true;
             return(ingredientSet);
         }
     }
     return(IngredientSet.Get(id));
 }
        public void Update(int activeIngredientId)
        {
            Ingredient ingredient = Ingredient.Get(activeIngredientId);

            // Yield
            if (ingredient.ExtendedIngredientYield != ExtendedIngredientYield)
            {
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredient.Id,
                                         ingredient.ExtendedIngredientYield, ExtendedIngredientYield,
                                         MeasurementUnit.None, -1);
                ingredient.UpdateExtendedIngredientYield(ExtendedIngredientYield);
            }

            // Added Ingredients
            foreach (IngredientSet ingredientSet in _ingredientSetsAdded)
            {
                ingredientSet.SetExtendedIngredientId(activeIngredientId);
                ingredientSet.Update();
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                         ingredientSet.IngredientId, null, ingredientSet.Amount, ingredientSet.MeasurementUnit,
                                         activeIngredientId);
            }

            // Changed Ingredients
            foreach (IngredientSet ingredientSet in _ingredientSetsNeedingUpdate)
            {
                IngredientSet original  = IngredientSet.Get(ingredientSet.Id);
                double        oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit,
                                                                 ingredientSet.MeasurementUnit);
                ingredientSet.Update();
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                         ingredientSet.IngredientId, oldAmount, ingredientSet.Amount, ingredientSet.MeasurementUnit,
                                         activeIngredientId);
            }

            // Removed Ingredients
            foreach (IngredientSet ingredientSet in _ingredientSetsRemoved)
            {
                IngredientSet original = IngredientSet.Get(ingredientSet.Id);
                IngredientSet.Delete(ingredientSet.Id);
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                         ingredientSet.IngredientId, original.Amount, null, original.MeasurementUnit,
                                         activeIngredientId);
            }

            _ingredientSetsAdded.Clear();
            _ingredientSetsNeedingUpdate.Clear();
            _ingredientSetsRemoved.Clear();
        }