Beispiel #1
0
        public async Task HandleAsync(DeleteParcel command)
        {
            var parcel = await _parcelRepository.GetAsync(command.ParcelId);

            if (parcel is null)
            {
                throw new ParcelNotFoundException(command.ParcelId);
            }

            var identity = _appContext.Identity;

            if (identity.IsAuthenticated && identity.Id != parcel.CustomerId && !identity.IsAdmin)
            {
                throw new UnauthorizedParcelAccessException(parcel.Id, identity.Id);
            }

            if (parcel.AddedToOrder)
            {
                throw new CannotDeleteParcelException(command.ParcelId);
            }

            await _parcelRepository.DeleteAsync(command.ParcelId);

            await _messageBroker.PublishAsync(new ParcelDeleted(command.ParcelId));
        }
Beispiel #2
0
        public async Task HandleAsync(ParcelAddedToOrder @event)
        {
            var parcel = await _parcelRepository.GetAsync(@event.ParcelId);

            if (parcel is null)
            {
                return;
            }

            parcel.AddToOrder(@event.OrderId);
            await _parcelRepository.UpdateAsync(parcel);
        }
Beispiel #3
0
        public async Task HandleAsync(ParcelDeletedFromOrder @event)
        {
            var parcel = await _parcelRepository.GetAsync(@event.ParcelId);

            if (parcel is null)
            {
                return;
            }

            parcel.DeleteFromOrder();
            await _parcelRepository.UpdateAsync(parcel);
        }
        public async Task HandleAsync(DeleteParcel command)
        {
            var parcel = await _parcelRepository.GetAsync(command.Id);

            if (parcel is null)
            {
                throw new ParcelNotFoundException(command.Id);
            }

            if (parcel.AddedToOrder)
            {
                throw new CannotDeleteParcelException(command.Id);
            }

            await _parcelRepository.DeleteAsync(command.Id);

            _logger.LogInformation($"Deleted a parcel with id: {command.Id}");
            await _messageBroker.PublishAsync(new ParcelDeleted(command.Id));
        }