Exemplo n.º 1
0
        public bool Insert(HUTModels.Recipe model)
        {
            try
            {
                Recipe recipe = new Recipe()
                {
                    Archived = model.Archived, DateEntered = model.DateEntered, Description = model.Description
                };

                repo.Create(recipe);
                repo.Save();

                if (model.Ingredients?.Count > 0)
                {
                    int?recipeId = GetIdByDescriptionAndDateEntered(model.Description, model.DateEntered);

                    if (recipeId != null)
                    {
                        IngredientBLL bll = new IngredientBLL(this.repo);

                        foreach (HUTModels.Ingredient ingredient in model.Ingredients)
                        {
                            ingredient.RecipeId = (int)recipeId;
                            bll.Insert(ingredient);
                        }
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool Delete(int recipeId)
        {
            try
            {
                // delete all the child ingredients first by getting them and looping to delete them all (not very efficient)
                // there needs to be a better way to do this en masse
                HUTModels.Recipe recipe = GetRecipeWithIngredients(recipeId);

                IngredientBLL bll = new IngredientBLL(this.repo);

                foreach (HUTModels.Ingredient ingredient in recipe.Ingredients)
                {
                    bll.Delete(ingredient.IngredientId);
                }

                repo.Delete <Recipe>(recipeId);
                repo.Save();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public HUTModels.Recipe GetRecipeWithIngredients(int recipeId)
        {
            IngredientBLL ingredientBLL = new IngredientBLL(this.repo);

            // must be done in two steps due to not using the context directly
            // getting the related data does not work with this repo
            HUTDataAccessLayerSQL.Recipe recipe = repo.GetById <HUTDataAccessLayerSQL.Recipe>(recipeId);
            HUTModels.Recipe             model  = new HUTModels.Recipe()
            {
                Archived    = recipe.Archived,
                DateEntered = recipe.DateEntered,
                Description = recipe.Description,
                RecipeId    = recipe.RecipeId,
                Ingredients = ingredientBLL.GetPerRecipe(recipeId)
            };

            return(model);
        }