Example #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));
        }
Example #2
0
        public ActionResult <PlatformReadDto> CreatePlatform(PlatformCreateDto platformCreate)
        {
            try
            {
                //Validations
                if (platformCreate == null)
                {
                    return(NotFound());
                }

                //Create
                var platform = _mapper.Map <Platform>(platformCreate);
                _repository.CreatePlatform(platform);
                _repository.SaveChanges();

                //Read
                var platformRead = _repository.GetPlatformById(platform.Id);

                //Response
                return(CreatedAtRoute(nameof(GetPlatformById), new { Id = platformRead.Id }, platformRead));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Example #3
0
        public ActionResult <PlatformReadDto> CreatePlatform(PlatformCreateDto platformCreateDto)
        {
            var platformModel = _mapper.Map <Platform>(platformCreateDto);

            _repository.CreatePlatform(platformModel);
            _repository.SaveChanges();

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

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