Esempio n. 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));
        }
Esempio n. 2
0
        protected override async Task ExecuteInternalAsync(CancellationToken stoppingToken)
        {
            ParcelDto parcel = await parcelRepository.DeleteAsync().ConfigureAwait(false);

            if (parcel != null)
            {
                await messageBroker.PublishAsync(new ParcelDispatchedMessage { Parcel = parcel }).ConfigureAwait(false);
            }
        }
        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));
        }