コード例 #1
0
        public async Task Handle(CreateInventoryItem command)
        {
            InventoryItemEvents iie = new InventoryItemEvents(_inventoryEventRepository, command.AggregateId);

            var eventData = ((CreateInventoryItemData)command.EventData).InventoryItemData;

            if (await iie.ModelEventsCountAsync(command.AggregateId) > 0)
            {
                //if (await _inventoryEventRepository.ModelEventsCountAsync(command.AggregateId) > 0)
                throw new DuplicateAggregateException(
                          string.Format("AggregateId {0} already created an inventory item.", command.AggregateId));
            }

            await Task.WhenAll(
                iie.AppendEventAsync((IModelEvent <Guid>)command),
                _inventoryWriteRepository.AppendAsync(
                    command.AggregateId,
                    new InventoryItemDto()
            {
                Id = command.AggregateId,
                LastEventTimestamp = command.Timestamp,
                Name     = eventData.Name,
                IsActive = eventData.IsActive,
                Count    = eventData.Count,
                Note     = eventData.Note
            }
                    ));
        }
コード例 #2
0
 public async Task AddAsync(InventoryItemDto inventoryItem)
 {
     await _writeRepository.AppendAsync(inventoryItem.Id, inventoryItem);
 }