Ejemplo n.º 1
0
        public async Task <Unit> Handle(ThingDeletedEvent @event, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"---- Received {nameof(ThingDeletedEvent)} message: Thing.Guid = [{@event.Guid}] ----");

            var thing = await _thingRepository.GetByGuid(@event.Guid);

            if (thing == null)
            {
                return(await HandleNotExistingThing(@event));
            }

            thing.Deleted = true;
            await _unitOfWork.Commit();

            _logger.LogInformation($"---- Deleted {nameof(ThingDeletedEvent)} message: Thing.Guid = [{@event.Guid}] ----");
            return(await Task.FromResult(Unit.Value));
        }
Ejemplo n.º 2
0
        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));
        }