public async Task AddAsync(AddParcel request) { if (!Enum.TryParse<ParcelSize>(request.Size, true, out var size)) { throw new InvalidParcelSizeException(request.Size); } var parcel = new Parcel(request.Id, size, request.Address); await _parcelsRepository.AddAsync(parcel); }
public async Task HandleAsync(ParcelAdded @event) { var parcel = await _parcelsServiceClient.GetAsync(@event.ParcelId); if (parcel is null) { throw new Exception($"Parcel with id: {@event.ParcelId} was not found."); } await _parcelsRepository.AddAsync(new Parcel(@event.ParcelId, parcel.Address)); _logger.LogInformation($"Added a parcel with id: {@event.ParcelId}"); }
public async Task HandleAsync(AddParcel command) { if (!Enum.TryParse <Size>(command.Size, true, out var size)) { throw new ArgumentException($"Invalid parcel size: {size}."); } var parcel = new Parcel(command.ParcelId, size, command.Name, command.Address); await _parcelsRepository.AddAsync(parcel); _logger.LogInformation($"Added a parcel: {command.ParcelId:N}, address: {command.Address}."); await _dispatcher.PublishAsync(new ParcelAdded(command.ParcelId, command.Name, command.Address)); }
public async Task HandleAsync(ParcelAdded @event) { await _parcelsRepository.AddAsync(new Parcel(@event.ParcelId, @event.Name, @event.Address)); _logger.LogInformation($"Added a parcel: {@event.ParcelId:N} to deliveries module."); }