コード例 #1
0
        public void UpdateRecipe(RecipeUpdateDTO updatedRecipe)
        {
            _recipesRepository.UpdateRecipeSimpleValues(_mapper.Map <RecipeUpdateDTO, Recipe>(updatedRecipe));

            Recipe recipe = _recipesRepository.GetRecipeById(updatedRecipe.Id);

            UpdateRecipeProducts(recipe, updatedRecipe);
            UpdateRecipeTags(recipe, updatedRecipe);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: RecipesController.cs プロジェクト: adgryz/FoodNet
        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));
        }
コード例 #4
0
        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());
        }