Exemple #1
0
        public Response AddRecipe(AddRecipeRequest data)
        {
            Response response = new Response();

            try
            {
                BusinessFacade.Instance.AddRecipeToShoppingList(data.userId, data.recipeId);
                response.message = "Success";
            }
            catch (Exception ex)
            {
                response.message = ex.Message;
            }
            return(response);
        }
Exemple #2
0
        public AddRecipeResponse AddRecipe(AddRecipeRequest request)
        {
            int recipeId;
            List <Ingredient>         ingridiants = new List <Ingredient>();
            List <SRL_RecipeCategory> categories  = new List <SRL_RecipeCategory>();
            AddRecipeResponse         response    = new AddRecipeResponse();

            try
            {
                Recipe recipe = new Recipe();

                //if (fuRecipeImage.HasFile && fuRecipeImage.PostedFile != null && ImageHelper.IsImage(fuRecipeImage.PostedFile.FileName))
                //{
                //    Bitmap bitmap = ImageHelper.ResizeImage(new Bitmap(this.fuRecipeImage.PostedFile.InputStream, false), 300, 231);
                //    RecipePicture = ImageHelper.GetBitmapBytes(bitmap);
                //}

                recipe.RecipeName        = request.recipe.name;
                recipe.IsPublic          = request.recipe.shared;
                recipe.Description       = request.recipe.description;
                recipe.Tags              = request.recipe.tags;
                recipe.PreparationMethod = request.recipe.instructions;
                recipe.Remarks           = request.recipe.comments;
                recipe.Tools             = request.recipe.tools;
                recipe.DifficultyLevel   = request.recipe.level;
                recipe.PreperationTime   = GetTimeInMinutes(request.recipe.prepareFor, request.recipe.prepareUnit);
                recipe.CookingTime       = this.GetTimeInMinutes(request.recipe.cookFor, request.recipe.cookUnit);
                recipe.Servings          = request.recipe.servings;
                recipe.UserId            = request.recipe.userId;

                //recipe.VideoLink = request.link;
                //recipe.Picture = this.RecipePicture;

                request.recipe.ingredients.ForEach(item =>
                {
                    Ingredient ingredient = new Ingredient
                    {
                        FoodId            = item.id,
                        FoodName          = item.name,
                        MeasurementUnitId = item.measureUnit,
                        Quantity          = (decimal)item.quantity + (decimal)item.fraction,
                        Remarks           = item.text
                    };
                    ingridiants.Add(ingredient);
                });

                request.categories.ForEach(item =>
                {
                    SRL_RecipeCategory category = new SRL_RecipeCategory(0, item.id, item.name);
                    categories.Add(category);
                });


                BusinessFacade.Instance.SaveRecipe(recipe, ingridiants, categories, true, out recipeId);
            }
            catch
            {
            }

            return(response);
        }