Пример #1
0
        public async Task <IActionResult> Create(IngredientViewModel ingredientVm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var ingredientDto = ingredientVm.MapToDto();

                    await _ingredientServices.AddIngredient(ingredientDto);

                    _toast.AddSuccessToastMessage($"You successfully added a new ingredient : {ingredientDto.Name} !");
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    _toast.AddErrorToastMessage(ex.Message);
                    ViewBag.ErrorTitle = "";
                    return(View("Error"));
                }
            }
            _toast.AddErrorToastMessage($"Invalid Model state!");
            return(View(ingredientVm));
        }