public async Task <IActionResult> GetRecipeById(int id) { var singleRecipe = await _repository.GetRecipeById(id); if (singleRecipe == null) { return(StatusCode(404, new { status = "not found", statusCode = 404, message = $"Recipe with id {id} is not found!" })); } var mappedRecipe = _mapper.Map <RecipeReadDto>(singleRecipe); return(StatusCode(200, new { status = "success", statusCode = 200, message = "Data successfully retrieved!", data = mappedRecipe })); }
public RecipeDto ServiceGetRecipeById(int id) { var result = _recipeRepository.GetRecipeById(id); if (result == null) { return(null); } result.Ingredients = _ingredientService.ServiceGenerateList(id).ToList(); return(result); }
public IActionResult Get([FromRoute] int id) { if (!RecipeExists(id)) { _logger.LogWarning($"Recipe with id: {id} does not exist."); return(NotFound()); } Recipe recipe = _recipeRepo.GetRecipeById(id); _logger.LogInformation($"Getting recipe with id: {id}"); return(Ok(recipe)); }
public RecipeDto GetRecipeById(int id) { var recipe = _recipeRepository.GetRecipeById(id); return(recipe); }