Example #1
0
        public async Task <IActionResult> GetAllActiveStores()
        {
            var query           = new AllActiveStoresQuery();
            var storeReadModels = await queryDispatcher.DispatchAsync(query, default);

            var storeContracts = activeStoreToContractConverter.ToContract(storeReadModels);

            return(Ok(storeContracts));
        }
Example #2
0
        public async Task <IEnumerable <StoreReadModel> > HandleAsync(AllActiveStoresQuery query, CancellationToken cancellationToken)
        {
            var activeStores          = (await storeRepository.GetAsync(cancellationToken)).ToList();
            var itemCountPerStoreDict = new Dictionary <StoreId, int>();

            foreach (var store in activeStores)
            {
                var storeId = new StoreId(store.Id.Value);
                var items   = (await itemRepository.FindByAsync(storeId, cancellationToken)).ToList();

                itemCountPerStoreDict.Add(storeId, items.Count);
            }

            cancellationToken.ThrowIfCancellationRequested();

            return(activeStores.Select(store => store.ToStoreReadModel(itemCountPerStoreDict[store.Id])));
        }