public void UpdateRecipe(RecipeUpdateDTO updatedRecipe) { _recipesRepository.UpdateRecipeSimpleValues(_mapper.Map <RecipeUpdateDTO, Recipe>(updatedRecipe)); Recipe recipe = _recipesRepository.GetRecipeById(updatedRecipe.Id); UpdateRecipeProducts(recipe, updatedRecipe); UpdateRecipeTags(recipe, updatedRecipe); }
private RecipeUpdateDTO RecipeToRecipeUpdateDTO(Recipe recipe) { RecipeUpdateDTO recipeDTO = GetMapper().Map <Recipe, RecipeUpdateDTO>(recipe); recipeDTO.Products = new List <ProductDTO>(); recipe.RecipeProducts.ForEach(rp => recipeDTO.Products.Add( GetMapper().Map <Product, ProductDTO>(productsList.Where(p => p.Id == rp.ProductId).Single()))); recipeDTO.Tags = new List <TagDTO>(); recipe.RecipeTags.ForEach(rt => recipeDTO.Tags.Add( GetMapper().Map <Tag, TagDTO>(tagsList.Where(t => t.Id == rt.TagId).Single()))); return(recipeDTO); }
public IActionResult AddRecipe([FromBody] BlankRecipeUpdateDTO newRecipe) { RecipeUpdateDTO newRecipeWithUser = new RecipeUpdateDTO { Id = newRecipe.Id, Title = newRecipe.Title, Description = newRecipe.Description, Products = newRecipe.Products, Tags = newRecipe.Tags, IsPrivate = newRecipe.IsPrivate, UserId = GetUserId(), }; _recipesDTOFacade.AddRecipe(newRecipeWithUser); return(Json(true)); }
public void UpdateAddsRecipeTags() { InitFields(); RecipesDTOFacade recipesDTOFacade = new RecipesDTOFacade( recipesRepositoryMock.Object, poorProductsRepositoryMock.Object, poorTagsRepositoryMock.Object, GetMapper()); tempUpdatingRecipe = recipe1.DeepCopy(); RecipeUpdateDTO recipeDTO = RecipeToRecipeUpdateDTO(tempUpdatingRecipe); tempUpdatingRecipe.RecipeTags = new List <RecipeTag>(); recipesDTOFacade.UpdateRecipe(recipeDTO); Assert.Equal(2, tempUpdatingRecipe.RecipeTags.Count()); }