Пример #1
0
        public async Task <ActionResult <PlatformReadDto> > CreatePlatform(PlatformCreateDto platformCreateDto)
        {
            var platform = _mapper.Map <Platform>(platformCreateDto);

            _repo.CreatePlatform(platform);

            var platformReadDto = _mapper.Map <PlatformReadDto>(platform);

            //send sync message (directly to service)
            try
            {
                await _commandDataClient.SendPlatformToCommand(platformReadDto);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"--> Could not send synchronously, exception: {ex.Message}");
            }

            //send async message (to message bus)
            try
            {
                var platformPublishedDto = _mapper.Map <PlatformPublishedDto>(platformReadDto);
                platformPublishedDto.Event = "Platform_Published";
                _messageBusClient.PublishNewPlatform(platformPublishedDto);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"--> Could not send asynchronously, exception: {ex.Message}");
            }

            return(CreatedAtRoute(nameof(GetPlatformById), new { id = platformReadDto.Id }, platformReadDto));
        }