Пример #1
0
        public OutputDtoQueryItem Create(int categoryId, InputDtoAddItem inputDtoAddItem)
        {
            var categoryFromDto = _categoryRepository.GetById(categoryId);

            var itemFromDto = new Item
            {
                Label           = inputDtoAddItem.Label,
                Price           = inputDtoAddItem.Price,
                ImageItem       = inputDtoAddItem.ImageItem,
                DescriptionItem = inputDtoAddItem.DescriptionItem,
                Category        = categoryFromDto
            };

            var itemInDb = _itemRepository.Create(categoryId, itemFromDto);

            return(new OutputDtoQueryItem
            {
                Id = itemInDb.Id,
                Label = itemInDb.Label,
                Price = itemInDb.Price,
                ImageItem = itemInDb.ImageItem,
                DescriptionItem = itemInDb.DescriptionItem,
                ItemCategory = new OutputDtoQueryItem.Category
                {
                    Id = itemInDb.Category.Id,
                    Title = itemInDb.Category.Title
                }
            });
        }
Пример #2
0
 public ActionResult <OutputDtoQueryItem> AddItem(int categoryId,
                                                  [FromBody] InputDtoAddItem item)
 {
     return(Ok(_itemService.Create(categoryId, item)));
 }