Esempio n. 1
0
        /// <summary>
        /// Converts a usage of an ingredient within a recipe to an IngredientAggregation object, suitable for aggregating with other usages of the same ingredient.
        /// </summary>
        /// <param name="usage">An IngredientUsage object, usually from a recipe.</param>
        /// <returns>An IngredientAggregation object, usually to be combined with other uses of that ingredient to form a shopping list.</returns>
        public virtual IngredientAggregation ConvertIngredientUsage(IngredientUsage usage)
        {
            // TODO: Does this method need to be part of the context?  Perhaps IngredientUsage should have a method to convert to an aggregation

            var ingredient = this.ReadIngredient(usage.Ingredient.Id);
            if (ingredient == null)
            {
                throw new IngredientNotFoundException();
            }

            var aggregation = new IngredientAggregation(ingredient);
            aggregation.AddUsage(usage);

            return aggregation;
        }
Esempio n. 2
0
        /// <summary>
        /// Converts a usage of an ingredient within a recipe to an IngredientAggregation object, suitable for aggregating with other usages of the same ingredient.
        /// </summary>
        /// <param name="usage">An IngredientUsage object, usually from a recipe.</param>
        /// <returns>An IngredientAggregation object, usually to be combined with other uses of that ingredient to form a shopping list.</returns>
        public IngredientAggregation ConvertIngredientUsage(IngredientUsage usage)
        {
            //TODO: Does this method need to be part of the context?  Perhaps IngredientUsage should have a method to convert to an aggregation

             var ing = ReadIngredient(usage.Ingredient.Id);
             if (ing == null)
            throw new IngredientNotFoundException();

             var a = new IngredientAggregation(ing);
             a.AddUsage(usage);

             return a;
        }