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

            var place = await _placeRepository.GetByGuid(@event.Guid);

            if (place != null)
            {
                _logger.LogInformation($"---- Place with Guid = [{@event.Guid}] already exists. Skipping event ----");
                return(await Task.FromResult(Unit.Value));
            }

            var user = await _userRepository.GetByGuid(@event.UserGuid);

            place = _placeMappingService.Map(@event, user.Id);
            if (@event.ParentPlaceGuid != null)
            {
                var parentPlace = await _placeRepository.GetByGuid((Guid)@event.ParentPlaceGuid);

                place.ParentLocationId = parentPlace.Id;
            }

            _placeRepository.Add(place);
            await _unitOfWork.Commit();

            _logger.LogInformation($"---- Saved {nameof(PlaceCreatedEvent)} message: Place.Guid = [{@event.Guid}] Place.Id = [{place.Id}]----");

            return(await Task.FromResult(Unit.Value));
        }
Exemplo n.º 2
0
        public async Task <Unit> Handle(PlaceUpdatedEvent @event, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"---- Received {nameof(PlaceUpdatedEvent)} message: Place.Guid = [{@event.Guid}] ----");

            var place = await _placeRepository.GetByGuid(@event.Guid);

            if (place == null)
            {
                return(await HandleNotExistingPlace(@event));
            }

            _placeMappingService.Map(@event, place);
            await _unitOfWork.Commit();

            _logger.LogInformation($"---- Updated {nameof(PlaceUpdatedEvent)} message: Place.Guid = [{@event.Guid}] ----");

            return(await Task.FromResult(Unit.Value));
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <PlaceListDto> > GetPlaces()
        {
            _logger.LogInformation("{class}.{method} Invoked", nameof(PlaceQueryService), nameof(GetPlaces));

            var userGuid = _httpContextUserService.GetUserGuid();
            var places   = await _placeRepository.GetPlaces(userGuid);

            return(_placeMappingService.Map(places));
        }
Exemplo n.º 4
0
        public async Task <int> CreatePlace(CreatePlaceDto createPlaceDto)
        {
            _logger.LogInformation("{class}.{method} with dto = [{@dto}] Invoked", nameof(PlaceCommandService), nameof(CreatePlace), createPlaceDto);

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

            var place = _placeMappingService.Map(createPlaceDto, user);

            _placeRepository.Add(place);
            await _unitOfWork.Commit();

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

            var @event = _placeMappingService.MapToPlaceCreatedEvent(place);

            _eventBusPublisher.Publish(@event);

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

            return(place.Id);
        }