public ActionResult Edit(Recipe recipe, HttpPostedFileBase Image)
        {
            if (recipe.Image != null)
            {
                Recipe image = repo.Get(recipe.RecipeId);
                string tmp   = Path.Combine(Server.MapPath(image.Image.ToString())).ToString();
                System.IO.File.Delete(tmp);

                int UserId = Int32.Parse(Session["UserID"].ToString());
                recipe.UserId = UserId;
                String sExt      = Path.GetExtension(Image.FileName).ToLower();
                String imagePath = "/Content/images/recipe/" + recipe.RecipeName + " " + recipe.UserId + sExt;
                string temp      = recipe.RecipeName + " " + recipe.UserId + sExt;
                //var fileName = Path.GetFileName(Image.FileName);
                var path = Path.Combine(Server.MapPath("~/Content/images/recipe/"), temp);
                Image.SaveAs(path);

                recipe.Image = imagePath;
                this.repo.Update(recipe);
                return(RedirectToAction("Details", "Recipe", new { id = recipe.RecipeId }));
            }
            else
            {
                Recipe image = repo.Get(recipe.RecipeId);

                string tmp = image.Image.ToString();

                recipe.Image = tmp;
                this.repo.Update(recipe);
                return(RedirectToAction("Details", "Recipe", new { id = recipe.RecipeId }));
            }
        }
예제 #2
0
        public async Task <IReadOnlyCollection <Recipe> > Search(string criteria, string category)
        {
            var resolvedCriteria = string.IsNullOrWhiteSpace(criteria) ? null : criteria;
            var resolvedCategory = string.IsNullOrWhiteSpace(category) ? null : category;

            var data = _repository.Get(resolvedCriteria, resolvedCategory);

            return(data);
        }
예제 #3
0
        public async Task <List <RecipeModel> > GetRecipeByKeyword(string keyword)
        {
            RecipeRepository repo = new RecipeRepository(_config, _loggerFactory);
            var response          = await repo.Get(keyword);

            return(response.ToList());
        }
예제 #4
0
        public ActionResult Details(int id)
        {
            var repo   = new RecipeRepository();
            var recipe = repo.Get(id);

            return(View(recipe));
        }
        public void ChangeDescription(int idRecipe)
        {
            Console.Write("\n    Enter recipe description: ");
            string description = Validation.NullOrEmptyText(Console.ReadLine());
            var    recipe      = RecipeRepository.Get(idRecipe);

            recipe.Description = description;
            RecipeRepository.Update(recipe);
            UnitOfWork.SaveAllData();
        }
        public void Edit(int id)
        {
            Console.Write("\n    Enter the name of the recipe: ");
            string nameRecipe = RecipeRepository.IsNameMustNotExist(Console.ReadLine());
            var    recipe     = RecipeRepository.Get(id);

            recipe.Name = nameRecipe;
            RecipeRepository.Update(recipe);
            UnitOfWork.SaveAllData();
        }
예제 #7
0
        public ActionResult Edit(int id)
        {
            var       repo   = new RecipeRepository();
            RecipeDto recipe = repo.Get(id);

            if (recipe == null)
            {
                return(HttpNotFound("The recipe you requested does not exist"));
            }

            return(View(recipe));
        }
        public async Task <string> GenerateShoppingCart(string words, string stores, Prj4databaseContext context)
        {
            string initString = "" +
                                "<html>";
            string endString = "</html>";

            string bodystring = "";

            string[] storeSplit = new string[8];

            if (stores != null)
            {
                storeSplit = stores.Split(';', StringSplitOptions.RemoveEmptyEntries);
            }

            RecipeQuery query = new RecipeQuery
            {
                LoadIngredientList = true,
                LoadRecipeCategory = true,
                SearchRecipe       = words,
                NumberOfRecipes    = 1,
                Stores             = storeSplit
            };

            RecipeRepository recipeRepository = new RecipeRepository(context);

            var result = await recipeRepository.Get(query);

            foreach (var recipe in result)
            {
                bodystring = "";
                string ingrediensstring = "";
                bodystring += "<h3><strong>Indkøbsliste</strong></h3>";

                bodystring += "<ul>";
                foreach (var ingredient in recipe.IngredientList.Ingredient)
                {
                    ingrediensstring += "<li class='p6'>" + ingredient.Name + " - " + " Købes i " + ingredient.Product.RetailChain.Name + " for " +
                                        ingredient.Product.Price + " kr. " + "</li>";
                }

                bodystring += ingrediensstring;
                bodystring += "</ul>" +
                              "</div>" +
                              "<br style='clear:both' />" +
                              "<ul>" +
                              "</div>";
            }
            return(initString + bodystring + endString);
        }
        public IHttpActionResult GenShoppingList(int[] recipeIdArray)
        {
            RecipeRepository repository      = new RecipeRepository();
            StringBuilder    IngredientNames = new StringBuilder();
            Recipe           recipe;

            foreach (var id in recipeIdArray)
            {
                recipe = repository.Get(id);
                IngredientNames.Append(recipe.Ingredients.Replace("\n", ""));
                IngredientNames.Append("\n");
            }

            return(Ok(IngredientNames.ToString()));
        }
        private void ButtonSave_Clicked(object sender, EventArgs e)
        {
            var result = repository.Get(recipe.Id);

            if (result != null)
            {
                DisplayAlert("Info", "Recipes already registered :)", "OK");
                return;
            }

            if (repository.Save(recipe))
            {
                DisplayAlert("Info", "Recipe save success :)", "OK");
                Navigation.PushAsync(new MainPage());
            }
            else
            {
                DisplayAlert("Info", "Something wrong :(", "OK");
                return;
            }
        }
        public void View(int idRecipe)
        {
            var recipe = RecipeRepository.Get(idRecipe);

            Console.WriteLine($"{new string('\n', 5)}    ________{recipe.Name}________\n\n");
            Console.WriteLine($"    {Validation.WrapText(10, recipe.Description, "\n    ")}");
            Console.WriteLine("\n    Required ingredients:\n");
            //ingredients recipe
            foreach (var a in AamountIngredientRepository.Items.Where(x => x.IdRecipe == recipe.Id))
            {
                foreach (var i in ingredientRepository.Items.Where(x => x.Id == a.IdIngredient))
                {
                    Console.WriteLine($"    {i.Name} - {a.Amount} {a.Unit}");
                }
            }
            //steps recipe
            Console.WriteLine("\n    Сooking steps:\n");
            foreach (var s in CookingStepRepository.Items.Where(x => x.IdRecipe == recipe.Id).OrderBy(x => x.Step))
            {
                Console.WriteLine($"    {s.Step}. {Validation.WrapText(10, s.Name, "\n       ")}");
            }
        }
 public int GetIdCategory(int idRecipe)
 {
     return(RecipeRepository.Get(idRecipe).IdCategory);
 }
        public async Task <string> ShowRecipeSmallViewSearchAsync(string word, string stores, Prj4databaseContext context)
        {
            string initString = "" + "<html>";
            string style      = "<head>" +
                                "<style>" +

                                ".viewOfRecipe{" +
                                "width: 60%;" +
                                "height: 200px;" +
                                "border: 2px solid;" +
                                "padding: 2px;" +
                                "margin: 20px;}" +

                                ".img1{" +
                                "display: block;" +
                                "position: absolute;" +
                                "width: 350px;" +
                                "height: 200px;}" +

                                ".textForPrice{" +
                                "display: block;" +
                                "position: relative;" +
                                "float: left;" +
                                "margin-left: 355px;" +
                                "font-size: 20px;}" +
                                "</style>" +
                                "</head> ";
            string endString = "</html>";

            string bodystring = "";

            HtmlCalculator calculator = new HtmlCalculator();

            string[] storeSplit     = new string[8];
            string[] storeSplitfake = new string[8];

            if (stores != null)
            {
                storeSplit = stores.Split(';', StringSplitOptions.RemoveEmptyEntries);
            }

            RecipeQuery query = new RecipeQuery
            {
                SearchRecipe       = word,
                NumberOfRecipes    = 5,
                LoadIngredientList = true,
            };

            RecipeRepository recipeRepository = new RecipeRepository(context);

            var recipeQuery = await recipeRepository.Get(query);

            if (recipeQuery.Count() == 0)
            {
                return("Ingen opskrift fundet");
            }

            foreach (var recipe in recipeQuery)
            {
                double originalPrice = 0;
                double salePrice     = 0;
                double lowestPrice   = 0;
                if (stores == null)
                {
                    if (recipe.Price != null)
                    {
                        originalPrice = (double)recipe.Price;
                    }
                    if (recipe.SavingsAbsolute != null)
                    {
                        salePrice   = (double)recipe.SavingsAbsolute;
                        lowestPrice = (double)recipe.SavingsAbsolute;
                    }
                }
                else
                {
                    originalPrice = await calculator.NormalPrice(recipe, recipe.Name, storeSplit, context);

                    salePrice = await calculator.TotalPrice(recipe, recipe.Name, storeSplit, context);

                    lowestPrice = await calculator.TotalPrice(recipe, recipe.Name, storeSplitfake, context);
                }


                bodystring += "<div class='viewOfRecipe'>" +
                              "<div class='imageOfRecipe'>" +
                              "<a href='/#/Recipe/" + recipe.Name.Replace(" ", string.Empty).Replace("æ", string.Empty).Replace("ø", string.Empty).Replace("å", string.Empty) + "'>" +
                              "<img class='img1' src='" + recipe.ImgSrc + "' alt='recpieImg'></a>" +
                              "</div>" +
                              "<div class='textForPrice'>" +
                              "<div style='font-size: 25px;'>" +
                              "<a href='/#/Recipe/" + recipe.Name.Replace(" ", string.Empty).Replace("æ", string.Empty).Replace("ø", string.Empty).Replace("å", string.Empty) + "'>" +
                              recipe.Name +
                              "</a>" +
                              "<br />" +
                              "</div>" +
                              "Original pris: " + originalPrice + "kr." + " <br />" +
                              "Pris med rabat: " + salePrice + "kr." + "<br />" +
                              "Laveste mulige pris: " + lowestPrice + "kr." + "<br />" +
                              "</div>" +
                              "</div>";
            }
            return(initString + style + bodystring + endString);
        }
        public async Task <string> ShowRecipeFullView(string words, double antal, Prj4databaseContext context)
        {
            string initString = "" +
                                "<html>";
            string endString = "</html>";

            string bodystring = "";

            antal /= 4;

            RecipeQuery query = new RecipeQuery
            {
                LoadIngredientList = true,
                LoadRecipeCategory = true,
                SearchRecipe       = words,
                NumberOfRecipes    = 1,
            };

            RecipeRepository recipeRepository = new RecipeRepository(context);

            var result = await recipeRepository.Get(query);

            foreach (var recipe in result)
            {
                bodystring = "";
                string ingrediensstring = "";
                string directionsstring = "";
                bodystring += "<h1>" + recipe.Name + "</h1>" +
                              "<div class='recipe'>" +
                              "<div class='ingredienser'>" +
                              "<p class='p2'><span class='s1'>" + recipe.CookTime + " min tilberednings tid" +
                              "<div class='image'>" +
                              "<img src = '" + recipe.ImgSrc + "' height='400' width='700'/>" +
                              "</div>" +
                              "<br style='clear: both' />" +
                              "<h3 class='p3'><strong>Fremgangsmåde</strong></h3>" +
                              "<div class='i1'>" + "<ul>";

                foreach (var direction in recipe.Directions)
                {
                    directionsstring += "<li class='p5'>" + direction.Description + "</li>";
                }

                bodystring += directionsstring;
                bodystring += "</ul>" +
                              "<h3><strong>Ingredienser</strong></h3>" +
                              "<ul>";
                foreach (var ingredient in recipe.IngredientList.Ingredient)
                {
                    ingrediensstring += "<li class='p6'>" + (ingredient.Amount * antal) + ingredient.AmountUnit + " " + ingredient.Name +
                                        "</li>";
                }

                bodystring += ingrediensstring;
                bodystring += "</ul>" +
                              "</div>" +
                              "<br style='clear:both' />" +
                              "<ul>" +
                              "</div>";
            }
            return(initString + bodystring + endString);
        }