public async Task HandleAsync(DeleteParcel command) { var parcel = await _parcelsRepository.GetAsync(command.ParcelId); if (parcel is null) { throw new Exception($"Parcel: {command.ParcelId:N} was not found."); } if (parcel.Status != Status.Available) { throw new Exception($"Parcel: {command.ParcelId:N} cannot be deleted, status: {parcel.Status}."); } await _parcelsRepository.DeleteAsync(command.ParcelId); _logger.LogInformation($"Deleted a parcel: {command.ParcelId:N}."); await _dispatcher.PublishAsync(new ParcelDeleted(command.ParcelId)); }
public async Task HandleAsync(DeleteParcel command) { var parcel = await _parcelsRepository.GetAsync(command.ParcelId); if (parcel is null) { throw new Exception($"Parcel with id: {command.ParcelId} was not found."); } if (parcel.Status != Status.New) { throw new InvalidOperationException($"Parcel with id: {command.ParcelId} " + $"and status: {parcel.Status} cannot be deleted."); } await _parcelsRepository.DeleteAsync(command.ParcelId); await _messageBroker.PublishAsync(new ParcelDeleted(command.ParcelId)); _logger.LogInformation($"Deleted a parcel with id: {command.ParcelId}"); }
public async Task HandleAsync(ParcelDeleted @event) { await _parcelsRepository.DeleteAsync(@event.ParcelId); _logger.LogInformation($"Deleted a parcel with id: {@event.ParcelId}"); }
public async Task HandleAsync(ParcelDeleted @event) { await _parcelsRepository.DeleteAsync(@event.ParcelId); _logger.LogInformation($"Deleted a parcel: {@event.ParcelId:N} from deliveries module."); }