Esempio n. 1
0
        public async Task UpdateThing(int id, UpdateThingDto updateThingDto)
        {
            _logger.LogInformation("{class}.{method} with id = [{id}] Invoked", nameof(ThingCommandService), nameof(UpdateThing), id);

            var userGuid = _httpContextUserService.GetUserGuid();
            var thing    = await _thingRepository.GetById(id, userGuid);

            if (thing is null || thing.Deleted)
            {
                throw new EntityNotFoundException <Thing>($"Id = [{id}]");
            }

            _thingMappingService.Map(updateThingDto, thing);
            await _unitOfWork.Commit();

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

            var @event = _thingMappingService.MapToThingUpdatedEvent(thing);

            _eventBusPublisher.Publish(@event);

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