예제 #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 Handle(DeleteInventoryItem command)
        {
            InventoryItemEvents iie = new InventoryItemEvents(_inventoryEventRepository, command.AggregateId);

            // ToDo: Cache aggregate and attempt to update rather than regenerate
            InventoryItemAggregate iia = (InventoryItemAggregate)await iie.ModelAsync();

            await Task.WhenAll(
                iie.AppendEventAsync((IModelEvent <Guid>)command)
                , _inventoryWriteRepository.DeleteAsync(command.AggregateId)
                );
        }
예제 #3
0
        private async Task _HandleUpdate(AInventoryItemEvent command)
        {
            InventoryItemEvents iie = new InventoryItemEvents(_inventoryEventRepository, command.AggregateId);

            // ToDo: Cache aggregate and attempt to update rather than regenerate
            InventoryItemAggregate iia = (InventoryItemAggregate)await iie.ModelAsync();

            command.ApplyEventData(iia);

            await Task.WhenAll(
                iie.AppendEventAsync((IModelEvent <Guid>)command),
                _inventoryWriteRepository.UpdateAsync(
                    command.AggregateId,
                    new InventoryItemDto(iia)
                    ));
        }