public async Task <Unit> Handle(ThingCommand.Create message) { #pragma warning disable 618 var entity = new Domain.Thing(message.Id, message.Name).SetAddress(message.AddressLine, message.AddressZip); #pragma warning restore 618 if (_securityPoint.CanDoWork(entity)) { await _thingRepository.Add(entity); } return(Unit.Value); }
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); }
public async Task <Unit> Handle(ThingCreatedEvent @event, CancellationToken cancellationToken) { _logger.LogInformation($"---- Received {nameof(ThingCreatedEvent)} message: Thing.Guid = [{@event.Guid}] ----"); var thing = await _thingRepository.GetByGuid(@event.Guid); if (thing != null) { _logger.LogInformation($"---- Thing with Guid = [{@event.Guid}] already exists. Skipping event ----"); return(await Task.FromResult(Unit.Value)); } thing = _thingMappingService.Map(@event); _thingRepository.Add(thing); await _unitOfWork.Commit(); _logger.LogInformation($"---- Saved {nameof(ThingCreatedEvent)} message: Thing.Guid = [{@event.Guid}] Thing.Id = [{thing.Id}]----"); return(await Task.FromResult(Unit.Value)); }