public async Task <IActionResult> Create(CreateIngredientViewModel vm) { var ingredientDTO = this.ingredientToDTOMpper.MapFromViewModel(vm); await this.ingredientService.CreateIngredient(ingredientDTO); return(RedirectToAction("Index", "Ingredient")); }
public async Task <IActionResult> CreateIngredient(CreateIngredientViewModel model) { if (!this.ModelState.IsValid) { return(this.RedirectToAction(nameof(IngredientList))); } var mappedIngredient = this.mapper.Map <Ingredient>(model); await this.restaurantService.AddIngredient(mappedIngredient); return(this.RedirectToAction(nameof(CreateIngredient))); }
public ActionResult Create(int recipeId) { var recipe = _db.Recipes.Single(r => r.Id == recipeId); var recipeName = recipe.Name; var model = new CreateIngredientViewModel() { Amount = 1, Name = "", RecipeId = recipeId, RecipeName = recipeName }; return(View(model)); }
public ActionResult Create(CreateIngredientViewModel model) { try { if (ModelState.IsValid) { var recipe = _db.Recipes.Single(r => r.Id == model.RecipeId); var newIngredient = new Ingredient() { Name = model.Name, Amount = model.Amount }; recipe.Ingredients.Add(newIngredient); _db.Save(); return(RedirectToAction("details", "Recipe", new { id = model.RecipeId })); } throw new Exception("Form is invalid"); } catch { return(View(model)); } }
public async Task <IActionResult> Edit(CreateIngredientViewModel ingredientVM) { await this.ingredientService.UpdateIngredient(ingredientVM.Id, ingredientVM.Name); return(RedirectToAction("Index", "Ingredient")); }
public async Task <IActionResult> Delete(CreateIngredientViewModel ingredientVM) { await this.ingredientService.DeleteIngredient(ingredientVM.Id); return(RedirectToAction("Index", "Ingredient")); }