Exemplo n.º 1
0
        public async Task <IActionResult> CreateAsync([FromBody] RecipeCreateDto dto)
        {
            var recipe = new Recipe(dto.Title, dto.Description, dto.Instructions);

            var id = await _recipeRepository.CreateAsync(recipe);

            return(Created($"v1/recipe/{id}", null));
        }
Exemplo n.º 2
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 }));
        }
Exemplo n.º 3
0
        public ActionResult <RecipeReadDto> CreateRecipe(RecipeCreateDto recipeCreateDto)
        {
            var recipeModel = _mapper.Map <Recipe>(recipeCreateDto);

            _repository.CreateRecipe(recipeModel);
            _repository.SaveChanges();

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

            return(CreatedAtRoute(nameof(GetRecipeById),
                                  new { Id = RecipeReadDto.Id }, RecipeReadDto));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateRecipe([FromBody] RecipeCreateDto recipe)
        {
            var recipeEntity = _mapper.Map <Entities.Recipe>(recipe);

            _recipesRepository.AddRecipe(recipeEntity);
            await _recipesRepository.SaveChangesAsync();

            await _recipesRepository.GetRecipeAsync(recipeEntity.Id);

            return(CreatedAtRoute("GetRecipe",
                                  new { id = recipeEntity.Id },
                                  recipeEntity));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Create(RecipeCreateDto command)
        {
            await CommandDispatcher.DispatchAsync(command);

            return(Created($"api/recipes/{command.Name}", null));
        }