Пример #1
0
        public async Task <RecipeEntryStep> UpdateStep(string id, string stepId, [FromBody] UpdateRecipeStep value)
        {
            value.Id       = stepId.Trim();
            value.RecipeId = id.Trim();

            return(await _mediator.Send(value));
        }
Пример #2
0
        public async Task <RecipeEntryStep> Handle(UpdateRecipeStep request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Updating a 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");
            }

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

            var record = recipe.RecipeEntrySteps.FindIndex(c => c.Id == request.Id);

            if (record == -1)
            {
                throw new MissingRecordException($"Recipe Step with id: {request.Id} not found");
            }

            recipe.RecipeEntrySteps[record] = update;

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

            return(update);
        }