Beispiel #1
0
        public static UpdateRecipeRequestModel UpdateRecipeRequestModel(RecipeDTO model)
        {
            var ingrids = new List <IngredientRequestModel>();

            foreach (var ingr in model.Ingredients)
            {
                ingrids.Add(CreateIngredientRequestModel(ingr));
            }

            var nutritionDto = CreateNutritionRequestModel(model);

            var modelDto = new UpdateRecipeRequestModel()
            {
                Id                = model.Id,
                Name              = model.Name,
                PrepTime          = model.PrepTime,
                CookTime          = model.CookTime,
                ReadyIn           = model.ReadyIn,
                SkillRequired     = model.SkillRequired,
                Serves            = model.Serves,
                PreparationMethod = model.PreparationMethod.ToList(),
                Description       = model.Description,
                Nutrition         = nutritionDto,
                Ingredients       = ingrids
            };

            return(modelDto);
        }
 public UpdateRecipeCommand(UpdateRecipeRequestModel requestModel)
 {
     Id          = requestModel.Id;
     Name        = requestModel.Name;
     Description = requestModel.Description;
     ImagePath   = requestModel.ImagePath;
     Ingredients = requestModel.Ingredients?.Select(x => new RecipeIngredientListItemDto
     {
         Name   = x.Name.Trim(),
         Amount = x.Amount
     }).ToList();
 }
Beispiel #3
0
        public IActionResult UpdateRecipe(UpdateRecipeRequestModel request)
        {
            var mapped = mapper.Map <RecipeDTO>(request);

            var result = recipeService.UpdateRecipe(mapped);

            if (!result)
            {
                return(Conflict());
            }

            return(Ok(result));
        }
Beispiel #4
0
        public async Task <string> UpdateRecipe(UpdateRecipeRequestModel model)
        {
            var data = ConvertObjToJsonStringContent(model);

            using (HttpResponseMessage responseMessage = await apiClient.PostAsync(RecipeApiEndpoints.RecipeUpdate, data))
            {
                if (responseMessage.IsSuccessStatusCode)
                {
                    var result = await responseMessage.Content.ReadAsAsync <string>();

                    return(result);
                }
                else
                {
                    throw new Exception(responseMessage.ReasonPhrase);
                }
            }
        }
Beispiel #5
0
        public async Task <IActionResult> UpdateRecipe([FromBody] UpdateRecipeRequestModel model)
        {
            await _mediator.Send(new UpdateRecipeCommand(model));

            return(Ok());
        }