public ResultDto <IngredientDto> Update(UpdateIngredientViewModel ingredientViewModel) { var result = new ResultDto <IngredientDto>(); if (!_ingredientRepository.Exist(x => x.Id == ingredientViewModel.Id)) { result.Errors.Add(_Errors.IngredientDoesNotExist); } if (!_recipeRepository.Exist(x => x.Id == ingredientViewModel.RecipeId)) { result.Errors.Add(_Errors.RecipeDoesNotExist); } if (result.IsError) { return(result); } var ingredient = _mapper.Map <Ingredient>(ingredientViewModel); if (_ingredientRepository.Update(ingredient) == 0) { result.Errors.Add(_Errors.SaveFail); return(result); } result.SuccessResult = _mapper.Map <IngredientDto>(ingredient); return(result); }
public IActionResult UpdateIngredient([FromBody] UpdateIngredientViewModel ingredientViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _ingredientService.Update(ingredientViewModel); if (result.IsError) { return(BadRequest(result)); } return(Ok(result)); }