protected async Task UpdateParcelStatusAsync(Guid parcelId, Action <Parcel> update)
        {
            var parcel = await _parcelsRepository.GetAsync(parcelId);

            update(parcel);
            await _parcelsRepository.UpdateAsync(parcel);
        }
Exemplo n.º 2
0
        public async Task HandleAsync(DeliveryCompleted @event)
        {
            var parcel = await _parcelsRepository.GetAsync(@event.ParcelId);

            if (parcel is null)
            {
                throw new InvalidOperationException($"Parcel with id: {@event.ParcelId} was not found.");
            }

            parcel.CompleteDelivery();
            await _parcelsRepository.UpdateAsync(parcel);

            _logger.LogInformation($"The delivery for parcel with id: {@event.ParcelId} has completed.");
        }
        public async Task HandleAsync(DeliveryFailed @event)
        {
            var parcel = await _parcelsRepository.GetAsync(@event.ParcelId);

            if (parcel is null)
            {
                throw new InvalidOperationException($"Parcel with id: {@event.ParcelId} was not found.");
            }

            parcel.FailDelivery(@event.Reason);
            await _parcelsRepository.UpdateAsync(parcel);

            _logger.LogInformation($"The delivery for parcel with id: {@event.ParcelId} has failed " +
                                   $"reason: {@event.Reason}.");
        }