public async Task HandleAsync(AddParcel command) { if (!Enum.TryParse <Variant>(command.Variant, true, out var variant)) { throw new InvalidParcelVariantException(command.Variant); } if (!Enum.TryParse <Size>(command.Size, true, out var size)) { throw new InvalidParcelSizeException(command.Size); } var parcel = new Parcel(command.Id, command.CustomerId, variant, size, command.Name, command.Description, _dateTimeProvider.Now); await _parcelRepository.AddAsync(parcel); _logger.LogInformation($"Added a parcel with id: {command.Id} for customer: {command.CustomerId}"); await _messageBroker.PublishAsync(new ParcelAdded(command.Id)); }
public async Task HandleAsync(AddParcel command) { if (!Enum.TryParse <Variant>(command.Variant, true, out var variant)) { throw new InvalidParcelVariantException(command.Variant); } if (!Enum.TryParse <Size>(command.Size, true, out var size)) { throw new InvalidParcelSizeException(command.Size); } if (!(await _customerRepository.ExistsAsync(command.CustomerId))) { throw new CustomerNotFoundException(command.CustomerId); } var parcel = new Parcel(command.ParcelId, command.CustomerId, variant, size, command.Name, command.Description, _dateTimeProvider.Now); await _parcelRepository.AddAsync(parcel); await _messageBroker.PublishAsync(new ParcelAdded(command.ParcelId)); }