Beispiel #1
0
        public async Task <RecipeEntryStep> Handle(AddRecipeStep request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Adding a new step for recipe", request);

            var recipe = await _recipeBookDataManager.Recipes.GetItemAsync(request.RecipeId);

            if (recipe == null)
            {
                throw new MissingRecordException($"Recipe with id: {request.RecipeId} not found");
            }

            if (recipe.OwnerId != _currentUser.UserId)
            {
                throw new RestrictedUpdateException("Cannot update a recipe you don't own");
            }

            if (recipe.RecipeEntrySteps == null)
            {
                recipe.RecipeEntrySteps = new List <RecipeEntryStep>();
            }

            var recipeStep = _mapper.Map <RecipeEntryStep>(request);

            recipe.RecipeEntrySteps.Add(recipeStep);

            await _recipeBookDataManager.Recipes.UpdateItemAsync(recipe.Id, recipe);

            return(recipeStep);
        }
Beispiel #2
0
        public async Task <RecipeEntryStep> AddStep(string id, [FromBody] AddRecipeStep value)
        {
            value.RecipeId = id;

            return(await _mediator.Send(value));
        }