public IActionResult Post([FromBody] Ingredient input)
        {
            var location = _linkGenerator.GetPathByAction("Get", "Ingredients");

            var ingredient = _mapper.Map <Ingredient>(input);

            _ingredientData.Add(ingredient);
            _ingredientData.Commit();
            return(Created(location, _mapper.Map <ApiIngredient>(ingredient)));
        }
        public IActionResult OnPost(int ingredientId)
        {
            var ingredient = ingredientData.Delete(ingredientId);

            ingredientData.Commit();

            if (ingredient == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            return(RedirectToPage("./List"));
        }
Beispiel #3
0
 public IActionResult OnPost(int recipeId)
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     if (Ingredient.Id > 0)
     {
         ingredientData.Update(Ingredient);
     }
     else
     {
         Ingredient.RecipeId = recipeId;
         ingredientData.Add(Ingredient);
     }
     ingredientData.Commit();
     return(RedirectToPage("./Detail", new { IngredientId = Ingredient.Id }));
 }
Beispiel #4
0
        public IActionResult Edit(Ingredient ingredient)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new IngredientViewModel {
                    Ingredient = ingredient
                };
                return(View(viewModel));
            }

            if (ingredient.Id > 0)
            {
                _ingredientData.Update(ingredient);
            }
            else
            {
                _ingredientData.Add(ingredient);
            }
            _ingredientData.Commit();
            return(RedirectToAction("Detail", new { area = "Common", ingredientId = ingredient.Id }));
        }