public async Task <IActionResult> AddIngredient(AddIngredientViewModel vm) { if (await _ingredientServices.IngredientWithThatNameExists(vm.Name)) { ModelState.AddModelError(string.Empty, "Ingredient with that name already exists."); return(View()); } await _ingredientServices.AddAsync(vm.Name, vm.Type); return(View()); }
public async Task <IActionResult> Add([FromBody] IngredientBasicViewModel vm) { var action = TempData["Action"].ToString(); if (ModelState.IsValid) { try { var ingredient = (await ingredientServices.AddAsync(vm.Name, vm.Unit)).MapToViewModel(); return(Json(ingredient)); } catch (ArgumentException ex) { TempData["Status"] = ex.Message; return(RedirectToAction(action, "Cocktails")); } } TempData["Status"] = "Invalid ingredient parameters"; return(RedirectToAction(action, "Cocktails")); }
public async Task <IActionResult> AddIngredient(AddIngredientViewModel vm) { await _ingredientServices.AddAsync(vm.Name, vm.Type); return(View()); }