public async Task <bool> HandleAsync(AddItemToShoppingListCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var list = await shoppingListRepository.FindByAsync(command.ShoppingListId, cancellationToken);

            if (list == null)
            {
                throw new DomainException(new ShoppingListNotFoundReason(command.ShoppingListId));
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (command.ItemId.IsActualId)
            {
                var actualId = new ItemId(command.ItemId.ActualId.Value);
                await addItemToShoppingListService.AddItemToShoppingList(list, actualId, command.SectionId, command.Quantity,
                                                                         cancellationToken);
            }
            else
            {
                var temporaryId = new TemporaryItemId(command.ItemId.OfflineId.Value);
                await addItemToShoppingListService.AddItemToShoppingList(list, temporaryId, command.SectionId,
                                                                         command.Quantity, cancellationToken);
            }

            cancellationToken.ThrowIfCancellationRequested();

            await shoppingListRepository.StoreAsync(list, cancellationToken);

            return(true);
        }
        public async Task ExchangeItemAsync(ItemId oldItemId, IStoreItem newItem, CancellationToken cancellationToken)
        {
            if (oldItemId is null)
            {
                throw new System.ArgumentNullException(nameof(oldItemId));
            }
            if (newItem is null)
            {
                throw new System.ArgumentNullException(nameof(newItem));
            }

            var shoppingListsWithOldItem = (await shoppingListRepository
                                            .FindActiveByAsync(oldItemId, cancellationToken))
                                           .ToList();

            foreach (var list in shoppingListsWithOldItem)
            {
                IShoppingListItem oldListItem = list.Items
                                                .First(i => i.Id == oldItemId);
                list.RemoveItem(oldListItem.Id);
                if (newItem.IsAvailableInStore(list.StoreId))
                {
                    var sectionId = newItem.GetDefaultSectionIdForStore(list.StoreId);
                    await addItemToShoppingListService.AddItemToShoppingList(list, newItem.Id, sectionId,
                                                                             oldListItem.Quantity, cancellationToken);

                    if (oldListItem.IsInBasket)
                    {
                        list.PutItemInBasket(newItem.Id);
                    }
                }

                await shoppingListRepository.StoreAsync(list, cancellationToken);
            }
        }