public async Task <IActionResult> CreateRecipe(RecipeCreateDto recipe) { var recipeModel = _mapper.Map <Recipe>(recipe); await _repository.CreateRecipe(recipeModel); await _repository.SaveChanges(); var convertRecipeToReadDto = _mapper.Map <RecipeReadDto>(recipeModel); return(CreatedAtRoute(nameof(GetRecipeById), new { Id = convertRecipeToReadDto.Id }, new { status = "created", statusCode = 201, message = "New data is successfully created!", data = convertRecipeToReadDto })); }
public IActionResult PutRecipe(int id, Recipe recipe) { if (id != recipe.Id) { _logger.LogWarning($"Route value id: {id} does not match recipe id: {recipe.Id}"); return(BadRequest()); } if (!RecipeExists(id)) { _logger.LogWarning($"Recipe with id: {id} does not exist."); return(NotFound()); } _recipeRepo.UpdateRecipe(recipe); _recipeRepo.SaveChanges(); _logger.LogInformation($"Recipe with id: {id} has been updated."); return(NoContent()); }