Esempio n. 1
0
        public async Task <int> CreateThing(CreateThingDto createThingDto)
        {
            _logger.LogInformation("{class}.{method} with dto = [{@dto}] Invoked", nameof(ThingCommandService), nameof(CreateThing), createThingDto);

            var userGuid = _httpContextUserService.GetUserGuid();
            var user     = await _userRepository.GetByGuid(userGuid);

            var thing = _thingMappingService.Map(createThingDto, user.Id);

            _thingRepository.Add(thing);
            await _unitOfWork.Commit();

            _logger.LogInformation("{entityName} with id = [{id}] has been created in local database", nameof(Thing), thing.Id);

            var @event = _thingMappingService.MapToThingCreatedEvent(thing);

            _eventBusPublisher.Publish(@event);

            _logger.LogInformation("{entityName} with id = [{id}] has been successfully created", nameof(Thing), thing.Id);
            return(thing.Id);
        }