Exemple #1
0
        public async Task <IActionResult> Post([FromBody] BrewViewModel brewForCreation)
        {
            if (brewForCreation == null)
            {
                return(BadRequest());
            }

            var brewForRepo = _mapper.Map <Brew>(brewForCreation);

            await _brewRepository.CreateBrewAsync(brewForRepo);

            var eventMessage = new SeedCatalogWithNewBrewIntegrationEvent(
                brewForRepo.BrewName,
                brewForRepo.BrewId,
                brewForRepo.StockQuantity,
                (int)Math.Round((double)(brewForRepo.StockQuantity / 3), 0)
                );

            try
            {
                _eventBus.Publish(eventMessage);
            }
            catch (Exception ex)
            {
                //_logger.Logit
            }

            return(CreatedAtAction(nameof(Get), new { id = brewForRepo.BrewId }));
        }