Exemplo n.º 1
0
        //Will take strings and builds a recipe

        public static Recipe BuildRecipe(string title, string directions, string recipeType, int recipeID, string yeild, string servingSize, string comment)
        {
            switch (recipeType)
            {
            case "Meal Item":
                MealItem m = new MealItem
                {
                    Title      = title,
                    Directions = directions,
                    RecipeType = recipeType,
                    RecipeID   = recipeID
                };
                if (yeild != null)
                {
                    m.Yield = yeild;
                }
                if (servingSize != null)
                {
                    m.ServingSize = servingSize;
                }
                if (comment != null)
                {
                    m.Comment = comment;
                }
                return(m);

            case "Dessert":
                Dessert d = new Dessert
                {
                    Title      = title,
                    Directions = directions,
                    RecipeType = recipeType,
                    RecipeID   = recipeID
                };
                if (yeild != null)
                {
                    d.Yield = yeild;
                }
                if (servingSize != null)
                {
                    d.ServingSize = servingSize;
                }
                if (comment != null)
                {
                    d.Comment = comment;
                }
                return(d);

            default:
                throw new Exception("Attempted to create a recipe of a non-supported type: " + recipeType);
            }
            ;
        }
Exemplo n.º 2
0
        private Recipe CreateRecipe(Recipe r)
        {
            switch (r.RecipeType)
            {
            case "Meal Item":
                MealItem m = new MealItem {
                    RecipeID   = r.RecipeID,
                    RecipeType = r.RecipeType,
                    Title      = r.Title,
                    Directions = r.Directions
                };
                if (r.Comment != null)
                {
                    m.Comment = r.Comment;
                }
                if (r.Yield != null)
                {
                    m.Yield = r.Yield;
                }
                if (r.ServingSize != null)
                {
                    m.ServingSize = r.ServingSize;
                }
                return(m);

            case "Dessert":
                Dessert d = new Dessert
                {
                    RecipeID    = r.RecipeID,
                    RecipeType  = r.RecipeType,
                    ServingSize = r.ServingSize,
                    Title       = r.Title,
                    Directions  = r.Directions
                };
                if (r.Comment != null)
                {
                    d.Comment = r.Comment;
                }
                if (r.Yield != null)
                {
                    d.Yield = r.Yield;
                }
                if (r.ServingSize != null)
                {
                    d.ServingSize = r.ServingSize;
                }
                return(d);

            default:
                return(r);
            }
        }