Esempio n. 1
0
        public async Task <IActionResult> CreateRecipe(RecipeCreateDto recipe)
        {
            var recipeModel = _mapper.Map <Recipe>(recipe);
            await _repository.CreateRecipe(recipeModel);

            await _repository.SaveChanges();

            var convertRecipeToReadDto = _mapper.Map <RecipeReadDto>(recipeModel);

            return(CreatedAtRoute(nameof(GetRecipeById), new { Id = convertRecipeToReadDto.Id }, new { status = "created", statusCode = 201, message = "New data is successfully created!", data = convertRecipeToReadDto }));
        }
Esempio n. 2
0
        public IEnumerable <RecipeDto> ServiceCreateRecipe(RecipeInputDto recipe)
        {
            var recipes = _recipeRepository.CreateRecipe(recipe);

            //why would database return null??
            // if(recipes == null)
            // {
            //     return NotFound();
            // }
            //some bussiness logic below
            foreach (var user in _userRepository.GetUsers())
            {
                sendEmailNotification(recipe, user.email, recipe.name);
            }
            return(ServiceGetRecipes());
        }