コード例 #1
0
        public ViewResult ViewRecipe(int id)
        {
            // Fetching particular recipe and then sending it to another view
            var           recipe      = recipeRepository.Recipes.Where(r => r.RecipeId == id).FirstOrDefault();
            var           ingredients = recipeRepository.Ingredients.Where(r => r.RecipeId == id).ToList();
            StringBuilder ingr        = new StringBuilder("");

            foreach (RecipeIngredients recIngr in ingredients)
            {
                ingr.Append(recIngr.IngredientName);
                ingr.Append(", ");
            }
            int length = ingr.ToString().Length;
            //var recipe = Repository.ListOfRecipes.Where(r => r.RecipeId == id).FirstOrDefault();
            RecipeIngredientMapping mapping = new RecipeIngredientMapping
            {
                ChefName    = recipe.ChefName,
                RecipeDesc  = recipe.RecipeDesc,
                RecipeName  = recipe.RecipeName,
                Ingredients = ingr.ToString().Substring(0, length - 2),
                PrepTime    = recipe.PrepTime,
                RecipeId    = recipe.RecipeId
            };

            return(View(mapping));
        }
コード例 #2
0
        public IActionResult AddRecipe(RecipeIngredientMapping recipe)
        {
            if (ModelState.IsValid)
            {
                recipeRepository.SaveRecipe(recipe);
                var msg = "swal('Success', '" + recipe.RecipeName.ToString() + " has been saved successfully" + "','success')" + "";

                TempData["message"] = msg;
                return(RedirectToAction("RecipeList"));
            }
            else
            {
                return(View(recipe));
            }
        }