Esempio n. 1
0
        public async Task <IActionResult> GetRecipe(int recipeId, [FromQuery] string scale)
        {
            var recipe = await _recipesService.Get(recipeId);

            if (recipe == null)
            {
                return(NotFound());
            }

            if (!string.IsNullOrEmpty(scale) && Amount.TryParse(scale, out Amount scaleAmount) && scaleAmount.ToString() != "1")
            {
                foreach (var ingredient in recipe.IngredientsList)
                {
                    if (ingredient.Amount.IsEmpty)
                    {
                        continue;
                    }

                    ingredient.Amount *= scaleAmount;

                    if (_alwaysDecimalUnits.Contains(ingredient.Unit))
                    {
                        ingredient.Amount = ingredient.Amount.ToDecimalAmount();
                    }
                }
            }

            return(Ok(recipe));
        }
Esempio n. 2
0
        public IActionResult Get(long id)
        {
            var recipe = _recipesService.Get(id);

            if (recipe == null)
            {
                return(NotFound());
            }

            return(File(recipe.Image, "image/jpeg"));
        }
        public IActionResult Show(long id)
        {
            var recipe = _recipesService.Get(id);

            return(View(recipe));
        }