public static Ingredient ToIngredientCreate(this IngredientCreateModel ingredient) { return(new Ingredient { Name = ingredient.Name }); }
public IActionResult Create(IngredientCreateModel ingredient) { if (ModelState.IsValid) { var ingToDB = ingredient.ToIngredientCreate(); ingredientsService.Create(ingToDB); return(RedirectToAction("Overview")); } return(View(ingredient)); }
public async Task <IActionResult> Create(IngredientCreateModel ingredientModel) { if (!ModelState.IsValid) { return(this.View(ingredientModel)); } bool isSuccessfullyCreated = await this.ingredients.Create(ingredientModel.Name, ingredientModel.QuantityInStock, ingredientModel.MinStockQuantityThreshold); if (isSuccessfullyCreated) { this.TempData[SuccessMessageKey] = string.Format(CookConstants.IngredientCreationSuccessMessage, ingredientModel.Name); } else { this.ModelState.AddModelError("Name", CookConstants.IngredientExistsErrorMessage); return(this.View(ingredientModel)); } return(this.RedirectToAction(nameof(IngredientsController.Index))); }
public IActionResult Create() { var ingredient = new IngredientCreateModel(); return(View(ingredient)); }