Beispiel #1
0
        public async Task <IActionResult> OnPostSaveRecipeAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                _context.Attach(Recipe).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                _context.Ingredient.UpdateRange(Ingredients);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeExists(Recipe.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Recipe = await _context.Recipe.FindAsync(id);

            if (Recipe != null)
            {
                _context.Recipe.Remove(Recipe);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }