コード例 #1
0
ファイル: FoodService.cs プロジェクト: jkulcsar/Cookbook
        /// <inheritdoc />
        public async Task CreateAsync(FoodCreate food)
        {
            var entity = _mapper.Map <Food>(food);
            await _repo.CreateAsync(entity);

            await _repo.SaveAsync();
        }
コード例 #2
0
        public async Task <ActionResult <FoodItemDto> > CreateAsync(CreateFoodItemDto createFoodItemDto)
        {
            var foodItem = new FoodItem
            {
                Name        = createFoodItemDto.name,
                Description = createFoodItemDto.description,
                Price       = createFoodItemDto.price
            };

            await _foodRepository.CreateAsync(foodItem);

            // Creates a 201 response that returns the created item.
            return(CreatedAtAction(nameof(GetByIdAsync), new { id = foodItem.Id }, foodItem));
        }