public async Task <ActionResult <ItemDto> > PostAsync(CreateItemDto createItemDto)
        {
            var item = new Item
            {
                Name        = createItemDto.Name,
                Description = createItemDto.Description,
                Price       = createItemDto.Price,
                CreatedDate = DateTimeOffset.UtcNow
            };

            await itemRepository.CreateAsync(item);

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = item.Id }, item));
        }
Exemple #2
0
        public async Task <ActionResult <ItemDto> > PostAsync(CreateItemDto createItemDto)
        {
            var item = new Item
            {
                Name        = createItemDto.Name,
                Description = createItemDto.Description,
                Price       = createItemDto.Price,
                CreatedDate = DateTimeOffset.UtcNow
            };

            await itemsRepository.CreateAsync(item);

            await publishEndpoint.Publish(new CatalogItemCreated(item.Id, item.Name, item.Description, item.Price));

            return(CreatedAtAction(nameof(GetByIdAsync), new { Id = item.Id }, item));
        }