예제 #1
0
        public async Task <IActionResult> UnSetIngredients(UnSetIngredientsViewModel entry)
        {
            if (ModelState.IsValid)
            {
                foreach (int riId in entry.RecipeIngredientIds)
                {
                    RecipeIngredient recipeIngredient = await _context.RecipeIngredient
                                                        .FirstOrDefaultAsync(r => r.Id == riId);

                    if (recipeIngredient != null)
                    {
                        //recipeIngredient.Ingredient.Name = "";
                        //recipeIngredient.Ingredient.ProteinsPerItem = 0;
                        //recipeIngredient.Ingredient.CaloriesPerItem = 0;
                        //recipeIngredient.Ingredient.SugarPerItem = 0;

                        _context.Update(recipeIngredient);
                    }
                }
                await _context.SaveChangesAsync();

                Recipe recipe = await _context.Recipe.FirstOrDefaultAsync(r => r.Id == entry.RecipeId);

                return(RedirectToAction(nameof(Index), new { rTitle = recipe.Title }));
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName")] Chef chef)
        {
            if (id != chef.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(chef);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChefExists(chef.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chef));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,PrepareTime,ImageUrl,Type,ChefId")] Recipe recipe)
        {
            if (id != recipe.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeExists(recipe.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ChefId"] = new SelectList(_context.Set <Chef>(), "Id", "FirstName", recipe.ChefId);
            return(View(recipe));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ImageUrl,CaloriesPerItem,ProteinsPerItem,VitaminsPerItem,IngredientFact")] Ingredient ingredient)
        {
            if (id != ingredient.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ingredient);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IngredientExists(ingredient.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ingredient));
        }