示例#1
0
        public ActionResult <IngredientReadDto> CreateIngredient(IngredientCreateDto ingredientCreateDto)
        {
            var ingredientModel = _mapper.Map <Ingredient>(ingredientCreateDto);

            _baseRepo.ingredient.CreateIngredient(ingredientModel);

            _baseRepo.SaveChanges();

            var ingredientReadDto = _mapper.Map <IngredientReadDto>(ingredientModel);

            return(CreatedAtRoute(nameof(GetIngredientById), new { Id = ingredientReadDto.IngredientId }, ingredientReadDto));
        }
示例#2
0
        public ActionResult <RecipeReadDto> CreateRecipe(RecipeCreateDto recipeCreateDto)
        {
            var    newRecipeId = Guid.NewGuid();
            var    userLoginId = HttpContext.GetUserLoginId();
            Recipe recipe      = new Recipe
            {
                RecipeId          = newRecipeId,
                Title             = recipeCreateDto.Title,
                Slug              = recipeCreateDto.Slug,
                Category          = recipeCreateDto.Category,
                Description       = recipeCreateDto.Description,
                RecipeIngredients = recipeCreateDto.RecipeIngredients.Select(x => new RecipeIngredients {
                    RecipeId = newRecipeId, IngredientId = x.IngredientId, Ingredient = x.Ingredient, Amount = x.Amount
                }).ToList()
            };

            _baseRepo.recipe.CreateRecipe(recipe, userLoginId);

            _baseRepo.SaveChanges();

            var recipeReadDto = _mapper.Map <RecipeReadDto>(recipe);

            return(CreatedAtRoute(nameof(GetRecipeById), new { Id = recipeReadDto.RecipeId.ToString() }, recipeReadDto));
        }